You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/07/28 03:11:27 UTC

[groovy] branch GROOVY_3_0_X updated (640e930 -> 273bb15)

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

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


    from 640e930  minor fix-ups
     new 7d30796  GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil
     new 273bb15  GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil (test)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy-xml/src/main/java/groovy/xml/XmlUtil.java    | 17 +++++++++++++++++
 .../test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy    | 16 ++++++++++++++++
 2 files changed, 33 insertions(+)


[groovy] 02/02: GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil (test)

Posted by pa...@apache.org.
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

commit 273bb15cc2887835458e36e34cb78423a7f67b1a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jul 28 12:50:57 2020 +1000

    GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil (test)
---
 .../src/test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy
index 323348f..3abcd31 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/Groovy4285Bug.groovy
@@ -39,4 +39,20 @@ class Groovy4285Bug extends GroovyShellTestCase {
         assert serializedXml.contains('<foo>')
         assert serializedXml.contains('bar')
     }
+
+    // GROOVY-9664
+    void testXMLSerializationOfLegacyGPathResultObject() {
+        assertScript '''
+            import groovy.util.slurpersupport.NodeChild
+            import groovy.xml.XmlUtil
+            
+            String xml = '<xml xmlns="http://example.com/ns"><abc><xyz>true</xyz></abc></xml>'
+            String name = 'abc'
+            
+            NodeChild parsed = new XmlSlurper().parseText(xml)
+            def node = parsed."$name"
+            
+            assert XmlUtil.serialize(node).contains('xyz>true</')
+        '''
+    }
 }


[groovy] 01/02: GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil

Posted by pa...@apache.org.
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

commit 7d30796ec2a9af0a06790b38e2e9b23e769cfc67
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jul 28 12:50:46 2020 +1000

    GROOVY-9664: Groovy 3.0 does not work with Groovy 2 code using groovy.xml.XmlUtil
---
 .../groovy-xml/src/main/java/groovy/xml/XmlUtil.java    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
index db8d8bb..1026a1d 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
@@ -406,6 +406,10 @@ public class XmlUtil {
     }
 
     private static String asString(GPathResult node) {
+        return asStringAdjusted(node);
+    }
+
+    private static String asStringAdjusted(Object node) {
         // little bit of hackery to avoid Groovy dependency in this file
         try {
             Object builder = Class.forName("groovy.xml.StreamingMarkupBuilder").getDeclaredConstructor().newInstance();
@@ -423,6 +427,9 @@ public class XmlUtil {
         if (writable instanceof GPathResult) {
             return asString((GPathResult) writable); //GROOVY-4285
         }
+        if (isOrExtendsLegacyGPathResult(writable.getClass())) {
+            return asStringAdjusted(writable); //GROOVY-4285 legacy case
+        }
         Writer sw = new StringBuilderWriter();
         try {
             writable.writeTo(sw);
@@ -432,6 +439,16 @@ public class XmlUtil {
         return sw.toString();
     }
 
+    private static boolean isOrExtendsLegacyGPathResult(Class candidate) {
+        if (candidate.getName().equals("java.lang.Object")) {
+            return false;
+        }
+        if (candidate.getName().endsWith(".slurpersupport.GPathResult")) {
+            return true;
+        }
+        return isOrExtendsLegacyGPathResult(candidate.getSuperclass());
+    }
+
     private static StreamSource asStreamSource(String xmlString) {
         return new StreamSource(new StringReader(xmlString));
     }