Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #86 #87

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/fasterxml/aalto/out/ByteXmlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,13 @@ public int writeCData(char[] cbuf, int offset, int len)
protected int writeCDataContents(char[] cbuf, int offset, int len)
throws IOException, XMLStreamException
{
if (_surrogate != 0) {
outputSurrogates(_surrogate, cbuf[offset]);
// reset the temporary surrogate storage
_surrogate = 0;
++offset;
--len;
}
/* Unlike with writeCharacters() and fastWriteName(), let's not
* worry about split buffers here: this is unlikely to become
* performance bottleneck. This allows keeping it simple; and
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/fasterxml/aalto/sax/TestSaxWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,29 @@ public void testSurrogateMemory2() throws Exception {
writer.writeEndTag(writer.constructName("testelement"));
writer.close(false);
}

public void testSurrogateMemory3() throws Exception {
// This test aims to produce the
// javax.xml.stream.XMLStreamException: Incomplete surrogate pair in content: first char 0xdfce, second 0x78
// error message. The issue was similar to the one described in testSurrogateMemory1(), except it happened in
// ByteXmlWriter#writeCDataContents(), where check for existing _surrogate was missing prior to the fix,
// as opposed to ByteXmlWriter#writeCharacters().
StringBuilder testText = new StringBuilder();
for (int i = 0; i < 511; i++)
testText.append('x');
testText.append("\uD835\uDFCE");
for (int i = 0; i < 512; i++)
testText.append('x');

WriterConfig writerConfig = new WriterConfig();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Utf8XmlWriter writer = new Utf8XmlWriter(writerConfig, byteArrayOutputStream);
writer.writeStartTagStart(writer.constructName("testelement"));
writer.writeCData(testText.toString());
writer.writeStartTagEnd();
writer.writeEndTag(writer.constructName("testelement"));
writer.close(false);

}

}
Loading