Skip to content

Commit 17e5950

Browse files
committed
Fix resource loading in HtmlSanitizerFuzzerTest
Replace org.apache.commons.codec.Resources.getInputStream() with standard Java class loader resource loading. The commons-codec Resources class uses the thread context class loader which may not have test resources on its classpath in certain environments like GitHub Actions with Maven Surefire. Using getClass().getClassLoader().getResourceAsStream() is more reliable because it uses the same class loader that loaded the test class, guaranteeing the resource will be found.
1 parent 16ce6bb commit 17e5950

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)