This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c2d3821 Add tests with external DTD
1c2d3821 is described below

commit 1c2d3821e67e08342b8cef4d4445c30b4a22daca
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Wed Dec 3 23:44:05 2025 +0100

    Add tests with external DTD
    
    Add tests for `XmlStringLookup` with an external DTD.
---
 .../commons/text/lookup/XmlStringLookupTest.java   | 15 ++++++++++++++
 .../apache/commons/text/document-external-dtd.dtd  | 20 ++++++++++++++++++
 .../apache/commons/text/document-external-dtd.xml  | 24 ++++++++++++++++++++++
 3 files changed, 59 insertions(+)

diff --git 
a/src/test/java/org/apache/commons/text/lookup/XmlStringLookupTest.java 
b/src/test/java/org/apache/commons/text/lookup/XmlStringLookupTest.java
index ead417dd..f0cc50ba 100644
--- a/src/test/java/org/apache/commons/text/lookup/XmlStringLookupTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/XmlStringLookupTest.java
@@ -76,6 +76,21 @@ class XmlStringLookupTest {
         assertEquals(DATA, new XmlStringLookup(EMPTY_MAP, 
XmlStringLookup.DEFAULT_XPATH_FEATURES).apply(key).trim());
     }
 
+    @Test
+    void testInterpolatorExternalDtdOff() {
+        final StringSubstitutor stringSubstitutor = 
StringSubstitutor.createInterpolator();
+        assertThrows(IllegalArgumentException.class, () -> 
stringSubstitutor.replace("${xml:" + DOC_DIR
+                + "document-external-dtd.xml:/document/content}"));
+    }
+
+    @Test
+    @SetSystemProperty(key = "XmlStringLookup.secure", value = "false")
+    void testInterpolatorExternalDtdOn() {
+        final StringSubstitutor stringSubstitutor = 
StringSubstitutor.createInterpolator();
+        assertEquals("This is an external entity.",
+                stringSubstitutor.replace("${xml:" + DOC_DIR + 
"document-external-dtd.xml:/document/content}").trim());
+    }
+
     @Test
     void testInterpolatorExternalEntityOff() {
         final StringSubstitutor stringSubstitutor = 
StringSubstitutor.createInterpolator();
diff --git 
a/src/test/resources/org/apache/commons/text/document-external-dtd.dtd 
b/src/test/resources/org/apache/commons/text/document-external-dtd.dtd
new file mode 100644
index 00000000..dbc9ca74
--- /dev/null
+++ b/src/test/resources/org/apache/commons/text/document-external-dtd.dtd
@@ -0,0 +1,20 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        https://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<!ENTITY externalEntity "This is an external entity.">
+<!ELEMENT document (title, content)>
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT content (#PCDATA)>
diff --git 
a/src/test/resources/org/apache/commons/text/document-external-dtd.xml 
b/src/test/resources/org/apache/commons/text/document-external-dtd.xml
new file mode 100644
index 00000000..158f5d83
--- /dev/null
+++ b/src/test/resources/org/apache/commons/text/document-external-dtd.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+     Licensed to the Apache Software Foundation (ASF) under one or more
+     contributor license agreements.  See the NOTICE file distributed with
+     this work for additional information regarding copyright ownership.
+     The ASF licenses this file to You under the Apache License, Version 2.0
+     (the "License"); you may not use this file except in compliance with
+     the License.  You may obtain a copy of the License at
+
+          https://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+  -->
+<!DOCTYPE document SYSTEM 
"src/test/resources/org/apache/commons/text/document-external-dtd.dtd">
+<document>
+  <title>Example of an External Entity</title>
+  <content>
+    &externalEntity;
+  </content>
+</document>

Reply via email to