-
Notifications
You must be signed in to change notification settings - Fork 711
IO-475: Fix UNC path prefix validation in FilenameUtils #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
IO-475: Fix UNC path prefix validation in FilenameUtils #825
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @MiriamCohenDev
Thank you for your PR. Please see my comments. Run mvn by itself before you push and fix any issues that come up.
| */ | ||
| package org.apache.commons.io; | ||
|
|
||
| import java.io.Console; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this import.
| if (!isSeparator(ch0) || !isSeparator(ch1)) { | ||
| return isSeparator(ch0) ? 1 : 0; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra blank line.
| } | ||
| try (BufferedOutputStream output3 = | ||
| new BufferedOutputStream(Files.newOutputStream(testFile1))) { | ||
| new BufferedOutputStream(Files.newOutputStream(testFile1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make spurious edits, it makes the PR larger and takes longer to review.
| assertEquals("D:\\a\\b\\c", FilenameUtils.separatorsToWindows("D:/a/b/c")); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files end in an empty line.
| assertEquals(SEP + SEP + "server.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt", FilenameUtils.normalize("\\\\server.example.org\\a\\b\\c.txt")); | ||
| assertEquals(SEP + SEP + "server.sub.example.org" + SEP + "a" + SEP + "b" + SEP + "c.txt", | ||
| FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt")); | ||
| FilenameUtils.normalize("\\\\server.sub.example.org\\a\\b\\c.txt")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make spurious edits, it makes the PR larger and takes longer to review.
|
Jira ticket is https://issues.apache.org/jira/browse/IO-475 |
51f04e9 to
090b9f9
Compare
090b9f9 to
64038e1
Compare
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @MiriamCohenDev
Thank you for your updates. You missed a few spots. It's simpler to review a PR if you don't delete assertions. Instead, change them to reflect the new behavior.
| void testEqualsNormalizedError_IO_128() { | ||
| assertFalse(FilenameUtils.equalsNormalizedOnSystem("//file.txt", "file.txt")); | ||
| assertFalse(FilenameUtils.equalsNormalizedOnSystem("file.txt", "//file.txt")); | ||
| assertFalse(FilenameUtils.equalsNormalizedOnSystem("//file.txt", "//file.txt")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertNull(FilenameUtils.getFullPathNoEndSeparator("1:")); | ||
| assertNull(FilenameUtils.getFullPathNoEndSeparator("1:a")); | ||
| assertNull(FilenameUtils.getFullPathNoEndSeparator("///a/b/c.txt")); | ||
| assertNull(FilenameUtils.getFullPathNoEndSeparator("//a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertNull(FilenameUtils.getPathNoEndSeparator("1:")); | ||
| assertNull(FilenameUtils.getPathNoEndSeparator("1:a")); | ||
| assertNull(FilenameUtils.getPathNoEndSeparator("///a/b/c.txt")); | ||
| assertNull(FilenameUtils.getPathNoEndSeparator("//a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertNull(FilenameUtils.getPrefix("1:")); | ||
| assertNull(FilenameUtils.getPrefix("1:a")); | ||
| assertNull(FilenameUtils.getPrefix("\\\\\\a\\b\\c.txt")); | ||
| assertNull(FilenameUtils.getPrefix("\\\\a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertEquals(-1, FilenameUtils.getPrefixLength("1:")); | ||
| assertEquals(-1, FilenameUtils.getPrefixLength("1:a")); | ||
| assertEquals(-1, FilenameUtils.getPrefixLength("\\\\\\a\\b\\c.txt")); | ||
| assertEquals(-1, FilenameUtils.getPrefixLength("\\\\a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertNull(FilenameUtils.normalize("1:")); | ||
| assertNull(FilenameUtils.normalize("1:a")); | ||
| assertNull(FilenameUtils.normalize("\\\\\\a\\b\\c.txt")); | ||
| assertNull(FilenameUtils.normalize("\\\\a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
| assertNull(FilenameUtils.normalizeNoEndSeparator("1:")); | ||
| assertNull(FilenameUtils.normalizeNoEndSeparator("1:a")); | ||
| assertNull(FilenameUtils.normalizeNoEndSeparator("\\\\\\a\\b\\c.txt")); | ||
| assertNull(FilenameUtils.normalizeNoEndSeparator("\\\\a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't delete assertions, instead change it to show the new behavior here.
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my previous comments, and run mvn without anything else and fix:
[INFO] --- checkstyle:3.6.0:check (default-cli) @ commons-io ---
[INFO] There are 16 errors reported by Checkstyle 13.0.0 with /Users/garygregory/git/commons/commons-io/src/conf/checkstyle.xml ruleset.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[940,13] (coding) FinalLocalVariable: Variable 'pos' should be declared final.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[941,16] (coding) FinalLocalVariable: Variable 'hostnamePart' should be declared final.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[942,9] (whitespace) WhitespaceAfter: 'if' is not followed by whitespace.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[942,9] (whitespace) WhitespaceAround: 'if' is not followed by whitespace.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[942,56] (whitespace) WhitespaceAround: '{' is not preceded with whitespace.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[945,9] (blocks) RightCurly: '}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[946,9] (whitespace) WhitespaceAfter: 'else' is not followed by whitespace.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[946,9] (whitespace) WhitespaceAround: 'else' is not followed by whitespace.
[ERROR] src/main/java/org/apache/commons/io/FilenameUtils.java:[946,13] (whitespace) WhitespaceAround: '{' is not preceded with whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[410,24] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[457,24] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[561,54] (whitespace) ParenPad: '(' is followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[780,21] (whitespace) ParenPad: '(' is followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[919,21] (whitespace) ParenPad: '(' is followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[992,21] (whitespace) ParenPad: '(' is followed by whitespace.
[ERROR] src/test/java/org/apache/commons/io/FilenameUtilsTest.java:[1132,21] (whitespace) ParenPad: '(' is followed by whitespace.
Fixes a bug in FilenameUtils#normalizeNoEndSeparator when handling UNC paths that do not end with a slash.
What:
How:
Why:
Testing:
Files changed:
src/main/java/org/apache/commons/io/FilenameUtils.javasrc/test/java/org/apache/commons/io/FilenameUtilsTest.java