Skip to content

Commit

Permalink
8314569: (fs) Improve normalization of UnixPath for input with traili…
Browse files Browse the repository at this point in the history
…ng slashes

Reviewed-by: alanb, bpb, rriggs
  • Loading branch information
Sergey Tsypanov authored and Alan Bateman committed Aug 29, 2023
1 parent 8b8182d commit 93188bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/java.base/unix/classes/sun/nio/fs/UnixPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.spi.FileSystemProvider;
import java.util.Arrays;
import java.util.Objects;

Expand Down Expand Up @@ -90,8 +89,9 @@ static String normalizeAndCheck(String input) {
checkNotNul(input, c);
prevChar = c;
}
if (prevChar == '/')
return normalize(input, n, n - 1);
if (prevChar == '/' && n > 1) {
return input.substring(0, n - 1);
}
return input;
}

Expand All @@ -109,7 +109,7 @@ private static String normalize(String input, int len, int off) {
return "/";
StringBuilder sb = new StringBuilder(input.length());
if (off > 0)
sb.append(input.substring(0, off));
sb.append(input, 0, off);
char prevChar = 0;
for (int i=off; i < n; i++) {
char c = input.charAt(i);
Expand Down

1 comment on commit 93188bd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.