From 8ef8611251417b655ce47f1de0ed69c68dc0377b Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Sat, 4 Sep 2021 13:02:14 +1000 Subject: [PATCH] feat: force standalone="yes" when standalone is set to true on the XML builder #1414 --- .../kotlin/au/com/dius/pact/consumer/xml/PactXmlBuilder.kt | 4 ++++ .../au/com/dius/pact/consumer/xml/PactXmlBuilderSpec.groovy | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/xml/PactXmlBuilder.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/xml/PactXmlBuilder.kt index 261b7b42e6..3c33a9f4a3 100644 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/xml/PactXmlBuilder.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/xml/PactXmlBuilder.kt @@ -77,6 +77,10 @@ class PactXmlBuilder @JvmOverloads constructor ( fun asBytes(charset: Charset? = null): ByteArray { val transformer = TransformerFactory.newInstance().newTransformer() transformer.setOutputProperty(OutputKeys.INDENT, "yes") + if (standalone) { + transformer.setOutputProperty(OutputKeys.STANDALONE, "yes") + } + val source = DOMSource(doc) val outputStream = ByteArrayOutputStream() val result = if (charset != null) { diff --git a/consumer/src/test/groovy/au/com/dius/pact/consumer/xml/PactXmlBuilderSpec.groovy b/consumer/src/test/groovy/au/com/dius/pact/consumer/xml/PactXmlBuilderSpec.groovy index 70451f8b2a..f5de755a41 100644 --- a/consumer/src/test/groovy/au/com/dius/pact/consumer/xml/PactXmlBuilderSpec.groovy +++ b/consumer/src/test/groovy/au/com/dius/pact/consumer/xml/PactXmlBuilderSpec.groovy @@ -134,7 +134,7 @@ class PactXmlBuilderSpec extends Specification { where: standalone | value - true | '' + true | '' false | '' } }