Skip to content

Commit 742cbc0

Browse files
authored
Merge pull request #366 from jospint/fix/resource-loading-in-fuzzer-test
Fix resource loading in HtmlSanitizerFuzzerTest
2 parents 16ce6bb + 17e5950 commit 742cbc0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

owasp-java-html-sanitizer/src/test/java/org/owasp/html/HtmlSanitizerFuzzerTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
package org.owasp.html;
3030

3131
import java.io.BufferedReader;
32+
import java.io.InputStream;
3233
import java.io.InputStreamReader;
3334
import java.nio.charset.StandardCharsets;
3435
import java.util.List;
@@ -37,8 +38,6 @@
3738
import java.util.concurrent.TimeUnit;
3839
import java.util.stream.Collectors;
3940

40-
import org.apache.commons.codec.Resources;
41-
4241
/**
4342
* Throws malformed inputs at the HTML sanitizer to try and crash it.
4443
* This test is stochastic -- not guaranteed to pass or fail consistently.
@@ -62,9 +61,17 @@ public void text(String textChunk) { /* do nothing */ }
6261
};
6362

6463
public final void testFuzzHtmlParser() throws Exception {
65-
String html = new BufferedReader(new InputStreamReader(
66-
Resources.getInputStream("benchmark-data/Yahoo!.html"),
67-
StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
64+
String html;
65+
try (InputStream resourceStream = getClass().getClassLoader()
66+
.getResourceAsStream("benchmark-data/Yahoo!.html")) {
67+
if (resourceStream == null) {
68+
throw new IllegalArgumentException(
69+
"Unable to resolve required resource: benchmark-data/Yahoo!.html");
70+
}
71+
html = new BufferedReader(new InputStreamReader(
72+
resourceStream,
73+
StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
74+
}
6875
int length = html.length();
6976

7077
char[] fuzzyHtml0 = new char[length];

0 commit comments

Comments
 (0)