Skip to content

Commit 1d7e523

Browse files
committed
SWS-434
1 parent a9aa325 commit 1d7e523

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,20 @@ public void endCDATA() throws SAXException {
147147
}
148148

149149
public void startEntity(String name) throws SAXException {
150-
charactersType = XMLStreamConstants.ENTITY_REFERENCE;
150+
if (!isPredefinedEntityReference(name)) {
151+
charactersType = XMLStreamConstants.ENTITY_REFERENCE;
152+
}
151153
}
152154

153155
public void endEntity(String name) throws SAXException {
154156
charactersType = XMLStreamConstants.CHARACTERS;
155157
}
156158

159+
private boolean isPredefinedEntityReference(String name) {
160+
return "lt".equals(name) || "gt".equals(name) || "amp".equals(name) || "quot".equals(name) ||
161+
"apos".equals(name);
162+
}
163+
157164
/*
158165
* Unsupported
159166
*/

core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@
3131

3232
public class AxiomHandlerTest extends XMLTestCase {
3333

34-
private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" +
35-
"<root xmlns='namespace'>" +
36-
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
37-
"</root>";
34+
private static final String XML_1 =
35+
"<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" + "<root xmlns='namespace'>" +
36+
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
37+
"</root>";
3838

39-
private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" +
40-
"<child xmlns='namespace2' />" + "</root>";
39+
private static final String XML_2_EXPECTED =
40+
"<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" + "<child xmlns='namespace2' />" +
41+
"</root>";
4142

4243
private static final String XML_2_SNIPPET =
4344
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
4445

46+
private static final String XML_3_ENTITY =
47+
"<predefined-entity-reference>&lt;&gt;&amp;&quot;&apos;</predefined-entity-reference>";
48+
4549
private AxiomHandler handler;
4650

4751
private OMDocument result;
@@ -87,4 +91,14 @@ public void testContentHandlerElement() throws Exception {
8791
result.serialize(bos);
8892
assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8"));
8993
}
94+
95+
public void testContentHandlerPredefinedEntityReference() throws Exception {
96+
handler = new AxiomHandler(result, factory);
97+
xmlReader.setContentHandler(handler);
98+
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
99+
xmlReader.parse(new InputSource(new StringReader(XML_3_ENTITY)));
100+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
101+
result.serialize(bos);
102+
assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8"));
103+
}
90104
}

0 commit comments

Comments
 (0)