This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 05c6237  GROOVY-10132: XmlUtil.serialize() Emoji bug
05c6237 is described below

commit 05c6237c7091695c91966def3fb1da86e1002fe7
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 ec73b79..e37c737 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
@@ -168,8 +168,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()

Reply via email to