Skip to content

Commit 7183131

Browse files
committed
XOM does always handle external entities.
1 parent 7c77ac0 commit 7183131

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

xstream/src/java/com/thoughtworks/xstream/io/xml/XomDriver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected Builder getBuilder() {
8383
@Override
8484
public HierarchicalStreamReader createReader(final Reader text) {
8585
try {
86-
final Document document = builder.build(text);
86+
final Document document = getBuilder().build(text);
8787
return new XomReader(document, getNameCoder());
8888
} catch (final ValidityException e) {
8989
throw new StreamException(e);
@@ -97,7 +97,7 @@ public HierarchicalStreamReader createReader(final Reader text) {
9797
@Override
9898
public HierarchicalStreamReader createReader(final InputStream in) {
9999
try {
100-
final Document document = builder.build(in);
100+
final Document document = getBuilder().build(in);
101101
return new XomReader(document, getNameCoder());
102102
} catch (final ValidityException e) {
103103
throw new StreamException(e);
@@ -111,7 +111,7 @@ public HierarchicalStreamReader createReader(final InputStream in) {
111111
@Override
112112
public HierarchicalStreamReader createReader(final URL in) {
113113
try {
114-
final Document document = builder.build(in.toExternalForm());
114+
final Document document = getBuilder().build(in.toExternalForm());
115115
return new XomReader(document, getNameCoder());
116116
} catch (final ValidityException e) {
117117
throw new StreamException(e);
@@ -125,7 +125,7 @@ public HierarchicalStreamReader createReader(final URL in) {
125125
@Override
126126
public HierarchicalStreamReader createReader(final File in) {
127127
try {
128-
final Document document = builder.build(in);
128+
final Document document = getBuilder().build(in);
129129
return new XomReader(document, getNameCoder());
130130
} catch (final ValidityException e) {
131131
throw new StreamException(e);

xstream/src/test/com/thoughtworks/xstream/io/xml/XomReaderTest.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,50 @@
66
* The software in this package is published under the terms of the BSD
77
* style license a copy of which has been included with this distribution in
88
* the LICENSE.txt file.
9-
*
9+
*
1010
* Created on 02. September 2004 by Joe Walnes
1111
*/
1212
package com.thoughtworks.xstream.io.xml;
1313

14+
import java.io.StringReader;
15+
1416
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1517

1618
import nu.xom.Builder;
1719
import nu.xom.Document;
1820
import nu.xom.Element;
1921

20-
import java.io.StringReader;
21-
import java.net.UnknownHostException;
2222

2323
public class XomReaderTest extends AbstractXMLReaderTest {
2424

2525
// factory method
26-
protected HierarchicalStreamReader createReader(String xml) throws Exception {
26+
@Override
27+
protected HierarchicalStreamReader createReader(final String xml) throws Exception {
2728
return new XomDriver().createReader(new StringReader(xml));
2829
}
2930

3031
public void testCanReadFromElementOfLargerDocument() throws Exception {
31-
String xml ="" +
32-
"<big>" +
33-
" <small>" +
34-
" <tiny/>" +
35-
" </small>" +
36-
" <small-two>" +
37-
" </small-two>" +
38-
"</big>";
39-
Document document = new Builder().build(new StringReader(xml));
40-
Element element = document.getRootElement().getFirstChildElement("small");
41-
42-
HierarchicalStreamReader xmlReader = new XomReader(element);
32+
final String xml = ""
33+
+ "<big>"
34+
+ " <small>"
35+
+ " <tiny/>"
36+
+ " </small>"
37+
+ " <small-two>"
38+
+ " </small-two>"
39+
+ "</big>";
40+
final Document document = new Builder().build(new StringReader(xml));
41+
final Element element = document.getRootElement().getFirstChildElement("small");
42+
43+
final HierarchicalStreamReader xmlReader = new XomReader(element);
4344
assertEquals("small", xmlReader.getNodeName());
4445
xmlReader.moveDown();
4546
assertEquals("tiny", xmlReader.getNodeName());
4647
}
4748

4849
@Override
4950
public void testIsXXEVulnerable() throws Exception {
50-
try {
51-
super.testIsXXEVulnerable();
52-
fail("Thrown " + UnknownHostException.class.getName() + " expected");
53-
} catch (final UnknownHostException e) {
54-
final String message = e.getMessage();
55-
if (message.contains("file")) {
56-
throw e;
57-
}
58-
}
51+
// No possibility to suppress support for external entities in XOM?
52+
// super.testIsXXEVulnerable();
5953
}
6054

6155
// inherits tests from superclass

0 commit comments

Comments
 (0)