Skip to content

Commit

Permalink
[bugfix] Correct an issue with character escaping intoduced in '[opti…
Browse files Browse the repository at this point in the history
…mise] Namespace and indentation performance fixes (commit c1a5e3e @alanpaxton (Alan Paxton)'
  • Loading branch information
adamretter committed Dec 4, 2024
1 parent 9676eef commit 7bcfa93
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public void characters(final CharSequence chars) throws TransformerException {
if(tagIsOpen) {
closeStartTag(false);
}
writer.append(chars);
writeChars(chars, false);
} catch(final IOException ioe) {
throw new TransformerException(ioe.getMessage(), ioe);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2014 Evolved Binary Ltd
*
* Changes made by Evolved Binary are proprietary and are not Open Source.
*/
package org.exist.util.serializer;

import org.apache.commons.io.output.StringBuilderWriter;
import org.junit.Test;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.util.Properties;

import static org.junit.Assert.assertEquals;

public class XMLWriterTest {

@Test
public void characters() throws IOException, TransformerException {
final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c";
final String expectedText = inputText.replace("&", "&");

final Properties outputProperties = new Properties();
outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

try (final StringBuilderWriter writer = new StringBuilderWriter()) {
final XMLWriter xmlWriter = new XMLWriter(writer);
xmlWriter.setOutputProperties(outputProperties);

xmlWriter.characters(inputText);

final String actualText = writer.toString();
assertEquals(expectedText, actualText);
}
}

@Test
public void writeChars() throws IOException {
final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c";
final String expectedText = inputText.replace("&", "&");

try (final StringBuilderWriter writer = new StringBuilderWriter()) {
final XMLWriter xmlWriter = new XMLWriter(writer);

xmlWriter.writeChars(inputText, false);

final String actualText = writer.toString();
assertEquals(expectedText, actualText);
}
}
}

0 comments on commit 7bcfa93

Please sign in to comment.