garydgregory commented on code in PR #543:
URL: https://github.com/apache/commons-vfs/pull/543#discussion_r1618758641
##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java:
##########
@@ -117,7 +118,10 @@ private boolean readSeparator() {
}
final String sub = path.substring(cursor, cursor + 3);
if (sub.equals(URLENCODED_SLASH_LC) ||
sub.equals(URLENCODED_SLASH_UC)) {
- cursor += 3;
+ path.setCharAt(cursor, SEPARATOR_CHAR);
+ path.delete(cursor + 1, cursor + 3);
Review Comment:
Should we use constants instead of magic numbers here? This would help
maintenance in the future IMO.
##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java:
##########
@@ -89,7 +90,7 @@ private boolean readNonSeparator() {
cursor++;
return true;
}
- final String sub = path.substring(cursor + 1, cursor + 3);
+ final String sub = path.substring(cursor, cursor + 3);
Review Comment:
Should we use constants instead of magic numbers here? This would help
maintenance in the future IMO.
##########
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserTest.java:
##########
@@ -99,4 +100,24 @@ public void testTypeOfNormalizedPath() {
fail(e);
}
}
+
+ @Test
+ public void testPathOfNormalizedPath() {
+ checkNormalizedPath("./Sub Folder/", "/Sub Folder");
+ checkNormalizedPath("./Sub Folder/../", "/");
+ checkNormalizedPath("./Sub Folder%2f..%2f", "/");
+ checkNormalizedPath("File.txt", "File.txt");
+ checkNormalizedPath("./Sub Folder/./File.txt", "/Sub Folder/File.txt");
+ checkNormalizedPath("./Sub Folder%2F.%2FFile.txt", "/Sub
Folder/File.txt");
+ }
+
+ private void checkNormalizedPath(String path, String normalized) {
+ StringBuilder pathBuilder = new StringBuilder(path);
+ try {
+ UriParser.normalisePath(pathBuilder);
+ assertEquals(normalized, pathBuilder.toString());
+ } catch (final FileSystemException e) {
+ fail(e);
Review Comment:
Let the exception percolate. This pattern clutters up the code IMO.
##########
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserTest.java:
##########
@@ -99,4 +100,24 @@ public void testTypeOfNormalizedPath() {
fail(e);
}
}
+
+ @Test
+ public void testPathOfNormalizedPath() {
+ checkNormalizedPath("./Sub Folder/", "/Sub Folder");
+ checkNormalizedPath("./Sub Folder/../", "/");
+ checkNormalizedPath("./Sub Folder%2f..%2f", "/");
+ checkNormalizedPath("File.txt", "File.txt");
+ checkNormalizedPath("./Sub Folder/./File.txt", "/Sub Folder/File.txt");
+ checkNormalizedPath("./Sub Folder%2F.%2FFile.txt", "/Sub
Folder/File.txt");
+ }
+
+ private void checkNormalizedPath(String path, String normalized) {
+ StringBuilder pathBuilder = new StringBuilder(path);
Review Comment:
Use `final` where you can.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]