Skip to content

Commit

Permalink
Do not remove starting file seperator on absolute paths if they aren'…
Browse files Browse the repository at this point in the history
…t under the base
  • Loading branch information
patrickptibco authored and slachiewicz committed Mar 25, 2024
1 parent 0fa03e9 commit f84e87a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,13 @@ public static String relativize(final String path, final File parentDir, final b
String platformSpecificPath;
if (p.normalize().startsWith(pd.normalize().toString())) {
platformSpecificPath = pd.relativize(p).toString();
if (removeInitialFileSep && platformSpecificPath.startsWith(File.separator)) {
platformSpecificPath = platformSpecificPath.substring(File.separator.length());
}
} else {
platformSpecificPath = p.toString();
}

if (removeInitialFileSep && platformSpecificPath.startsWith(File.separator)) {
platformSpecificPath = platformSpecificPath.substring(File.separator.length());
}

// NOTE: it appears this function is meant to preserve the file separator that was passed in the path
if (path.indexOf('\\') == -1) {
platformSpecificPath = platformSpecificPath.replace('\\', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ public void validateRelativizingPaths() throws Exception {
final String path = "/project/backend/foobar/my-schema.xsd";
final SortedMap<String, String> parentDir2Expected = new TreeMap<>();
parentDir2Expected.put("/", "project/backend/foobar/my-schema.xsd");
parentDir2Expected.put("", "project/backend/foobar/my-schema.xsd");
parentDir2Expected.put("", "/project/backend/foobar/my-schema.xsd");
parentDir2Expected.put("/project", "backend/foobar/my-schema.xsd");
parentDir2Expected.put("/not/a/path", "project/backend/foobar/my-schema.xsd");
parentDir2Expected.put("/not/a/path", "/project/backend/foobar/my-schema.xsd");
parentDir2Expected.put("/project/", "backend/foobar/my-schema.xsd");

// Act & Assert
Expand Down

0 comments on commit f84e87a

Please sign in to comment.