Skip to content
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

[IO-783] Remove NTFS ADS separator check in FilenameUtils.getExtension #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/main/java/org/apache/commons/io/FilenameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,6 @@ public static int indexOfExtension(final String fileName) throws IllegalArgument
if (fileName == null) {
return NOT_FOUND;
}
if (isSystemWindows()) {
// Special handling for NTFS ADS: Don't accept colon in the file name.
final int offset = fileName.indexOf(':', getAdsCriticalOffset(fileName));
if (offset != -1) {
throw new IllegalArgumentException("NTFS ADS separator (':') in file name is forbidden.");
}
}
final int extensionPos = fileName.lastIndexOf(EXTENSION_SEPARATOR);
final int lastSeparator = indexOfLastSeparator(fileName);
return lastSeparator > extensionPos ? NOT_FOUND : extensionPos;
Expand Down
10 changes: 1 addition & 9 deletions src/test/java/org/apache/commons/io/FilenameUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,7 @@ public void testGetExtension() {
assertEquals("", FilenameUtils.getExtension("a\\b\\c"));
assertEquals("", FilenameUtils.getExtension("C:\\temp\\foo.bar\\README"));
assertEquals("ext", FilenameUtils.getExtension("../filename.ext"));

if (FilenameUtils.isSystemWindows()) {
// Special case handling for NTFS ADS names
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> FilenameUtils.getExtension("foo.exe:bar.txt"));
assertEquals("NTFS ADS separator (':') in file name is forbidden.", e.getMessage());
} else {
// Upwards compatibility:
assertEquals("txt", FilenameUtils.getExtension("foo.exe:bar.txt"));
}
assertEquals("txt", FilenameUtils.getExtension("foo.exe:bar.txt"));
}

@Test
Expand Down