Skip to content

Commit ad3dfbd

Browse files
authored
Merge pull request #2 from augustd/safefile-npe
Fix NPE when passing just filename
2 parents 3e28605 + c9bb73b commit ad3dfbd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/java/org/owasp/fileio/SafeFile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public SafeFile(URI uri) throws ValidationException {
5353
}
5454

5555
private void doDirCheck(String path) throws ValidationException {
56+
if (path == null) return;
5657
Matcher m1 = DIR_BLACKLIST_PAT.matcher(path);
5758
if (m1.find()) {
5859
throw new ValidationException("Invalid directory", "Directory path (" + path + ") contains illegal character: " + m1.group());

src/test/java/org/owasp/fileio/SafeFileTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ public void testAlternateDataStream() {
151151
} catch (ValidationException expected) {
152152
}
153153
}
154+
155+
public void testSafeFileWithoutPath() {
156+
try {
157+
File sf = new SafeFile("hello.txt");
158+
} catch (ValidationException expected) {
159+
}
160+
}
154161

155162
static public String toHex(final byte b) {
156163
final char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

0 commit comments

Comments
 (0)