This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push: new efcfd33 GROOVY-10132: XmlUtil.serialize() Emoji bug efcfd33 is described below commit efcfd3308797d7a3c7527765ce6c74e48363355b Author: Paul King <pa...@asert.com.au> AuthorDate: Fri Jun 11 22:42:19 2021 +1000 GROOVY-10132: XmlUtil.serialize() Emoji bug --- .../groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java | 5 +++-- .../groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java index a9ce038..a67e432 100644 --- a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java +++ b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java @@ -175,8 +175,9 @@ public class StreamingMarkupWriter extends Writer { // High surrogate this.surrogatePair.append((char) c); this.haveHighSurrogate = true; - - } else if (!this.encoder.canEncode((char) c)) { + return; + } + if (!this.encoder.canEncode((char) c)) { this.writer.write("&#x"); this.writer.write(Integer.toHexString(c)); this.writer.write(';'); diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy index 02f0df1..e71076b 100644 --- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy +++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/XmlUtilTest.groovy @@ -45,6 +45,15 @@ class XmlUtilTest extends GroovyTestCase { assertXmlEquals(xml, XmlUtil.serialize(new XmlSlurper().parse(source))) } + def xml2 = '<?xml version="1.0" encoding="UTF-8"?><Name>🎁4</Name>' + + // GROOVY-10132 + void testSerializeOfSurrogate() { + def source = new InputSource(new StringReader(xml2)) + source.encoding = "UTF-8" + assertXmlEquals(xml2, XmlUtil.serialize(new XmlSlurper().parse(source))) + } + // GROOVY-5361 void testSchemaValidationUtilityMethod() { Locale dl = Locale.getDefault()