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/12/28 05:07:00 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-8850:
StreamingMarkupBuilder adds namespace on elements not expected
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 49aaa6c GROOVY-8850: StreamingMarkupBuilder adds namespace on elements not expected
49aaa6c is described below
commit 49aaa6c698dda2ac35e5453283fa8b49ae67cae7
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Dec 27 23:47:14 2020 +1000
GROOVY-8850: StreamingMarkupBuilder adds namespace on elements not expected
---
.../groovy/xml/StreamingMarkupBuilder.groovy | 2 +-
.../groovy/xml/StreamingMarkupBuilderTest.groovy | 39 ++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy
index b5e0a2e..dad32a4 100644
--- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy
+++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy
@@ -174,7 +174,7 @@ class StreamingMarkupBuilder extends AbstractStreamingBuilder {
} else {
out << ">"
- pendingStack.add pendingNamespaces.clone()
+ pendingStack.push pendingNamespaces.clone()
pendingNamespaces.clear()
body.each {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingMarkupBuilderTest.groovy b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingMarkupBuilderTest.groovy
index e83b6ab..5d579d7 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingMarkupBuilderTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/StreamingMarkupBuilderTest.groovy
@@ -48,6 +48,45 @@ class StreamingMarkupBuilderTest extends BuilderTestSupport {
assert result.contains("<one xml:lang='en'>First</one>")
}
+ // GROOVY-8850
+ void testStreamingMarkupBuilderAddingNamespaceCorrectly() {
+
+ def topics = ['<TOPIC>topic1</TOPIC>', '<TOPIC>topic2</TOPIC>', '<TOPIC>topic3</TOPIC>']
+
+ def addTrnUID = { b -> b.TRNUID('01234') }
+
+ def xml = new StreamingMarkupBuilder().bind { builder ->
+ mkp.xmlDeclaration()
+ mkp.declareNamespace('': 'http://www.dnb.com/GSRL/Vers7/Rls24',
+ 'xsi': 'http://www.w3.org/2001/XMLSchema-instance')
+ GSRL {
+ GSRLMSGSRQV1 {
+ SUBJUPDTRNRQ {
+ addTrnUID(builder)
+ SUBJUPDRQ {
+ topics.each{ topic -> mkp.yieldUnescaped topic }
+ }
+ }
+ }
+ }
+ }
+
+ assert XmlUtil.serialize(xml.toString()).normalize() == '''\
+<?xml version="1.0" encoding="UTF-8"?><GSRL xmlns="http://www.dnb.com/GSRL/Vers7/Rls24" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <GSRLMSGSRQV1>
+ <SUBJUPDTRNRQ>
+ <TRNUID>01234</TRNUID>
+ <SUBJUPDRQ>
+ <TOPIC>topic1</TOPIC>
+ <TOPIC>topic2</TOPIC>
+ <TOPIC>topic3</TOPIC>
+ </SUBJUPDRQ>
+ </SUBJUPDTRNRQ>
+ </GSRLMSGSRQV1>
+</GSRL>
+'''
+ }
+
protected assertExpectedXml(Closure markup, String expectedXml) {
assertExpectedXml markup, null, expectedXml
}