Skip to content

Commit 1c2d382

Browse files
committed
Add tests with external DTD
Add tests for `XmlStringLookup` with an external DTD.
1 parent ed3df4b commit 1c2d382

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/test/java/org/apache/commons/text/lookup/XmlStringLookupTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ void testExternalEntityOn() {
7676
assertEquals(DATA, new XmlStringLookup(EMPTY_MAP, XmlStringLookup.DEFAULT_XPATH_FEATURES).apply(key).trim());
7777
}
7878

79+
@Test
80+
void testInterpolatorExternalDtdOff() {
81+
final StringSubstitutor stringSubstitutor = StringSubstitutor.createInterpolator();
82+
assertThrows(IllegalArgumentException.class, () -> stringSubstitutor.replace("${xml:" + DOC_DIR
83+
+ "document-external-dtd.xml:/document/content}"));
84+
}
85+
86+
@Test
87+
@SetSystemProperty(key = "XmlStringLookup.secure", value = "false")
88+
void testInterpolatorExternalDtdOn() {
89+
final StringSubstitutor stringSubstitutor = StringSubstitutor.createInterpolator();
90+
assertEquals("This is an external entity.",
91+
stringSubstitutor.replace("${xml:" + DOC_DIR + "document-external-dtd.xml:/document/content}").trim());
92+
}
93+
7994
@Test
8095
void testInterpolatorExternalEntityOff() {
8196
final StringSubstitutor stringSubstitutor = StringSubstitutor.createInterpolator();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<!ENTITY externalEntity "This is an external entity.">
18+
<!ELEMENT document (title, content)>
19+
<!ELEMENT title (#PCDATA)>
20+
<!ELEMENT content (#PCDATA)>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!DOCTYPE document SYSTEM "src/test/resources/org/apache/commons/text/document-external-dtd.dtd">
19+
<document>
20+
<title>Example of an External Entity</title>
21+
<content>
22+
&externalEntity;
23+
</content>
24+
</document>

0 commit comments

Comments
 (0)