Skip to content

Commit d05ab34

Browse files
committed
Use explicitly File.separatorChar, and add comment
1 parent 3d76d92 commit d05ab34

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/org/opensolaris/opengrok/util/PathUtils.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,20 @@ public static String getRelativeToCanonical(String path, String canonical,
101101

102102
if (path.equals(canonical)) return "";
103103

104-
String path0 = path.replace('\\', '/');
105-
String normCanonical0 = canonical.replace('\\', File.separatorChar);
106-
String normCanonical = normCanonical0.endsWith(File.separator) ?
107-
normCanonical0 : normCanonical0 + File.separator;
104+
// The following fixup of \\ is really to allow
105+
// IndexDatabaseTest.testGetDefinitions() to succeed on Linux or macOS.
106+
// That test has an assertion that operation is the "same for windows
107+
// delimiters" and passes a path with backslashes. On Windows, the
108+
// following fixup would not be needed, since File and Paths recognize
109+
// backslash as a delimiter. On Linux and macOS, any backslash needs to
110+
// be normalized.
111+
path = path.replace('\\', File.separatorChar);
112+
canonical = canonical.replace('\\', File.separatorChar);
113+
String normCanonical = canonical.endsWith(File.separator) ?
114+
canonical : canonical + File.separator;
108115
Deque<String> tail = null;
109116

110-
File iterPath = new File(path0);
117+
File iterPath = new File(path);
111118
while (iterPath != null) {
112119
String iterCanon = iterPath.getCanonicalPath();
113120

0 commit comments

Comments
 (0)