Skip to content

Commit 6910589

Browse files
committed
[Misc] Prevent that PdfExportImplTest accesses w3.org
1 parent 571f00e commit 6910589

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/pdf/impl/PdfExportImplTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.ByteArrayOutputStream;
2424
import java.io.StringReader;
2525

26+
import javax.xml.XMLConstants;
2627
import javax.xml.parsers.DocumentBuilderFactory;
2728

2829
import org.junit.jupiter.api.BeforeEach;
@@ -153,7 +154,11 @@ void setUp() throws Exception
153154
this.cssProperties = "span { color:red; }";
154155

155156
// Set up HTML cleaner.
156-
Document htmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder()
157+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
158+
// Prevent network requests to w3.org to fetch the DTD.
159+
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
160+
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
161+
Document htmlDocument = factory.newDocumentBuilder()
157162
.parse(new ByteArrayInputStream(this.htmlContent.getBytes()));
158163
HTMLCleanerConfiguration cleanerConfiguration = new DefaultHTMLCleanerConfiguration();
159164
when(this.htmlCleaner.getDefaultConfiguration()).thenReturn(cleanerConfiguration);

0 commit comments

Comments
 (0)