You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2017/11/16 15:34:14 UTC
commons-io git commit: Add test of illegal replacement char
Repository: commons-io
Updated Branches:
refs/heads/master 84a0d9078 -> 10c8db1b1
Add test of illegal replacement char
Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/10c8db1b
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/10c8db1b
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/10c8db1b
Branch: refs/heads/master
Commit: 10c8db1b1ae0fd9be8b661dbf24643c0a9012d68
Parents: 84a0d90
Author: Sebb <se...@apache.org>
Authored: Thu Nov 16 15:33:58 2017 +0000
Committer: Sebb <se...@apache.org>
Committed: Thu Nov 16 15:33:58 2017 +0000
----------------------------------------------------------------------
src/main/java/org/apache/commons/io/FileSystem.java | 3 ++-
.../java/org/apache/commons/io/FileSystemTestCase.java | 13 ++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-io/blob/10c8db1b/src/main/java/org/apache/commons/io/FileSystem.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/FileSystem.java b/src/main/java/org/apache/commons/io/FileSystem.java
index fed5bd6..9a5f520 100644
--- a/src/main/java/org/apache/commons/io/FileSystem.java
+++ b/src/main/java/org/apache/commons/io/FileSystem.java
@@ -211,7 +211,8 @@ public enum FileSystem {
if (isIllegalFileNameChar(replacement)) {
throw new IllegalArgumentException(
String.format("The replacement character '%s' cannot be one of the %s illegal characters: %s",
- replacement, name(), Arrays.toString(illegalFileNameChars)));
+ // %s does not work properly with NUL
+ replacement == '\0' ? "\\0" : replacement, name(), Arrays.toString(illegalFileNameChars)));
}
final String truncated = candidate.length() > maxFileNameLength ? candidate.substring(0, maxFileNameLength)
: candidate;
http://git-wip-us.apache.org/repos/asf/commons-io/blob/10c8db1b/src/test/java/org/apache/commons/io/FileSystemTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/FileSystemTestCase.java b/src/test/java/org/apache/commons/io/FileSystemTestCase.java
index f5335c1..53a13d4 100644
--- a/src/test/java/org/apache/commons/io/FileSystemTestCase.java
+++ b/src/test/java/org/apache/commons/io/FileSystemTestCase.java
@@ -52,7 +52,7 @@ public class FileSystemTestCase {
for (char i = '0'; i < '9'; i++) {
Assert.assertEquals(i, fs.toLegalFileName(String.valueOf(i), replacement).charAt(0));
}
- }
+ }
@Test
public void testIsLegalName() {
@@ -63,4 +63,15 @@ public class FileSystemTestCase {
Assert.assertTrue(fs.name(), fs.isLegalFileName("0")); // Assume simple name always legal
}
}
+
+ @Test
+ public void testReplacementWithNUL() {
+ for (FileSystem fs : FileSystem.values()) {
+ try {
+ fs.toLegalFileName("Test", '\0'); // Assume NUL is always illegal
+ } catch (IllegalArgumentException iae) {
+ Assert.assertTrue(iae.getMessage(), iae.getMessage().startsWith("The replacement character '\\0'"));
+ }
+ }
+ }
}