Skip to content

Commit

Permalink
Fix eliding of root marker in root paths
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed May 21, 2022
1 parent db17b54 commit 34073ba
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private TrundlePath(final TrundleFileSystem fs, final TrundlePathType pathType,
this.fs = Objects.requireNonNull(fs);
this.pathType = Objects.requireNonNull(pathType);
this.root = Objects.requireNonNull(root);
this.path = elide(Objects.requireNonNull(path));
this.path = elideIfNeeded(root, Objects.requireNonNull(path));
this.componentIndexes = null;
this.hash = 0;
}
Expand Down Expand Up @@ -127,9 +127,13 @@ private static String normalize(final String original) {
return builder.substring(1);
}

private static String elideIfNeeded(final String root, final String path) {
return root.equals(path)? path : elide(path); // if root == path, then we are either in empty or root, which are special cased
}

private static String elide(final String path) {
final int last = path.length() - 1;
return path.charAt(last) == '/'? path.substring(0, last) : path; // TODO("Verify if this makes sense")
final int last;
return !path.isEmpty() && path.charAt(last = path.length() - 1) == '/'? path.substring(0, last) : path; // TODO("Verify if this makes sense")
}

@NotNull
Expand Down

0 comments on commit 34073ba

Please sign in to comment.