Skip to content

Commit 7bcfa93

Browse files
committed
[bugfix] Correct an issue with character escaping intoduced in '[optimise] Namespace and indentation performance fixes (commit c1a5e3e @alanpaxton (Alan Paxton)'
1 parent 9676eef commit 7bcfa93

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

exist-core/src/main/java/org/exist/util/serializer/XMLWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void characters(final CharSequence chars) throws TransformerException {
376376
if(tagIsOpen) {
377377
closeStartTag(false);
378378
}
379-
writer.append(chars);
379+
writeChars(chars, false);
380380
} catch(final IOException ioe) {
381381
throw new TransformerException(ioe.getMessage(), ioe);
382382
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2014 Evolved Binary Ltd
3+
*
4+
* Changes made by Evolved Binary are proprietary and are not Open Source.
5+
*/
6+
package org.exist.util.serializer;
7+
8+
import org.apache.commons.io.output.StringBuilderWriter;
9+
import org.junit.Test;
10+
11+
import javax.xml.transform.OutputKeys;
12+
import javax.xml.transform.TransformerException;
13+
import java.io.IOException;
14+
import java.util.Properties;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
public class XMLWriterTest {
19+
20+
@Test
21+
public void characters() throws IOException, TransformerException {
22+
final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c";
23+
final String expectedText = inputText.replace("&", "&");
24+
25+
final Properties outputProperties = new Properties();
26+
outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
27+
28+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
29+
final XMLWriter xmlWriter = new XMLWriter(writer);
30+
xmlWriter.setOutputProperties(outputProperties);
31+
32+
xmlWriter.characters(inputText);
33+
34+
final String actualText = writer.toString();
35+
assertEquals(expectedText, actualText);
36+
}
37+
}
38+
39+
@Test
40+
public void writeChars() throws IOException {
41+
final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c";
42+
final String expectedText = inputText.replace("&", "&");
43+
44+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
45+
final XMLWriter xmlWriter = new XMLWriter(writer);
46+
47+
xmlWriter.writeChars(inputText, false);
48+
49+
final String actualText = writer.toString();
50+
assertEquals(expectedText, actualText);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)