diff --git a/exist-core/src/main/java/org/exist/util/serializer/IndentingXMLWriter.java b/exist-core/src/main/java/org/exist/util/serializer/IndentingXMLWriter.java index 12a09abe46e..79f3152de8c 100644 --- a/exist-core/src/main/java/org/exist/util/serializer/IndentingXMLWriter.java +++ b/exist-core/src/main/java/org/exist/util/serializer/IndentingXMLWriter.java @@ -151,7 +151,7 @@ public void endDocument() throws TransformerException { @Override public void endDocumentType() throws TransformerException { super.endDocumentType(); - super.characters("\n"); + indent(); sameline = false; } @@ -197,11 +197,7 @@ protected void pushWhitespacePreserve(final CharSequence value) { protected void popWhitespacePreserve() { if (!whitespacePreserveStack.isEmpty() && Math.abs(whitespacePreserveStack.peek()) > level) { whitespacePreserveStack.pop(); - if (whitespacePreserveStack.isEmpty() || whitespacePreserveStack.peek() >= 0) { - whitespacePreserve = false; - } else { - whitespacePreserve = true; - } + whitespacePreserve = !whitespacePreserveStack.isEmpty() && whitespacePreserveStack.peek() < 0; } } diff --git a/exist-core/src/test/java/org/exist/util/serializer/HTML5WriterTest.java b/exist-core/src/test/java/org/exist/util/serializer/HTML5WriterTest.java index fc061031b91..a2bc2097f23 100644 --- a/exist-core/src/test/java/org/exist/util/serializer/HTML5WriterTest.java +++ b/exist-core/src/test/java/org/exist/util/serializer/HTML5WriterTest.java @@ -42,7 +42,7 @@ public void setUp() throws Exception { @Test public void testAttributeWithBooleanValue() throws Exception { - final String expected = "\n"; + final String expected = ""; final QName elQName = new QName("input"); writer.startElement(elQName); writer.attribute("checked", "checked"); @@ -54,7 +54,7 @@ public void testAttributeWithBooleanValue() throws Exception { @Test public void testAttributeWithNonBooleanValue() throws Exception { - final String expected = "\n"; + final String expected = ""; final QName elQName = new QName("input"); writer.startElement(elQName); writer.attribute("name", "name"); @@ -66,7 +66,7 @@ public void testAttributeWithNonBooleanValue() throws Exception { @Test public void testAttributeQNameWithBooleanValue() throws Exception { - final String expected = "\n"; + final String expected = ""; final QName elQName = new QName("input"); final QName attrQName = new QName("checked"); writer.startElement(elQName); @@ -79,7 +79,7 @@ public void testAttributeQNameWithBooleanValue() throws Exception { @Test public void testAttributeQNameWithNonBooleanValue() throws Exception { - final String expected = "\n"; + final String expected = ""; final QName elQName = new QName("input"); final QName attrQName = new QName("name"); writer.startElement(elQName); diff --git a/exist-core/src/test/java/org/exist/xmldb/SerializationTest.java b/exist-core/src/test/java/org/exist/xmldb/SerializationTest.java index b4de05229db..586420c5fbe 100644 --- a/exist-core/src/test/java/org/exist/xmldb/SerializationTest.java +++ b/exist-core/src/test/java/org/exist/xmldb/SerializationTest.java @@ -47,6 +47,7 @@ import java.util.Arrays; +import static javax.xml.transform.OutputKeys.INDENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -94,7 +95,7 @@ public class SerializationTest { private static final String XML_WITH_DOCTYPE = "\n" + - ""; + "\n asdf\n "; private static final XmldbURI TEST_XML_DOC_WITH_XMLDECL_URI = XmldbURI.create("test-with-xmldecl.xml"); @@ -177,6 +178,10 @@ public void xqueryUpdateNsTest() throws XMLDBException { @Test public void getDocTypeDefault() throws XMLDBException { final Resource res = testCollection.getResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString()); + // FIXME (JL): local and remote collections apparently have different output properties set + // INDENT is set to "no" for remote collections that's why it is explicitly set to true here + // Also, setting INDENT to "no" does not work for local collections and only somewhat for remote ones. + testCollection.setProperty(INDENT, "yes"); assertEquals(XML_WITH_DOCTYPE, res.getContent()); } diff --git a/exist-core/src/test/xquery/xquery3/serialize.xql b/exist-core/src/test/xquery/xquery3/serialize.xql index bea438d425f..fd49227a8e8 100644 --- a/exist-core/src/test/xquery/xquery3/serialize.xql +++ b/exist-core/src/test/xquery/xquery3/serialize.xql @@ -847,23 +847,27 @@ function ser:serialize-xml-134() { }; declare - %test:assertEquals(' ') + %test:assertEquals('') function ser:serialize-html-5-boolean-attribute-names() { -