Skip to content

Commit

Permalink
IO-567: Implement special case handling for NTFS ADS names
Browse files Browse the repository at this point in the history
fix checkstyle violation by replacing tabs with spaces
  • Loading branch information
PascalSchumacher committed Feb 4, 2018
1 parent cfb682e commit 27fb104
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/main/java/org/apache/commons/io/FilenameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,11 @@ public static int indexOfExtension(final String filename) throws IllegalArgument
return NOT_FOUND;
}
if (isSystemWindows()) {
// Special handling for NTFS ADS: Don't accept colon in the filename.
final int offset = filename.indexOf(':', getAdsCriticalOffset(filename));
if (offset != -1) {
throw new IllegalArgumentException("NTFS ADS separator (':') in filename is forbidden.");
}
// Special handling for NTFS ADS: Don't accept colon in the filename.
final int offset = filename.indexOf(':', getAdsCriticalOffset(filename));
if (offset != -1) {
throw new IllegalArgumentException("NTFS ADS separator (':') in filename is forbidden.");
}
}
final int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
final int lastSeparator = indexOfLastSeparator(filename);
Expand Down Expand Up @@ -1070,24 +1070,24 @@ public static String getExtension(final String filename) throws IllegalArgumentE
}

private static int getAdsCriticalOffset(String filename) {
// Step 1: Remove leading path segments.
int offset1 = filename.lastIndexOf(SYSTEM_SEPARATOR);
int offset2 = filename.lastIndexOf(OTHER_SEPARATOR);
if (offset1 == -1) {
if (offset2 == -1) {
return 0;
} else {
return offset2 + 1;
}
} else {
if (offset2 == -1) {
return offset1+1;
} else {
return Math.max(offset1, offset2)+1;
}
}
// Step 1: Remove leading path segments.
int offset1 = filename.lastIndexOf(SYSTEM_SEPARATOR);
int offset2 = filename.lastIndexOf(OTHER_SEPARATOR);
if (offset1 == -1) {
if (offset2 == -1) {
return 0;
} else {
return offset2 + 1;
}
} else {
if (offset2 == -1) {
return offset1 + 1;
} else {
return Math.max(offset1, offset2) + 1;
}
}
}

//-----------------------------------------------------------------------
/**
* Removes the extension from a filename.
Expand Down

0 comments on commit 27fb104

Please sign in to comment.