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() {
-
- => serialize($ser:opt-map-html5)
- => normalize-space()
+ serialize(, $ser:opt-map-html5)
};
declare
- %test:assertEquals('
')
+ %test:assertEquals('
')
function ser:serialize-html-5-empty-tags() {
-
- => serialize($ser:opt-map-html5)
- => normalize-space()
+ serialize(
, $ser:opt-map-html5)
};
+(: test for https://github.com/eXist-db/exist/issues/4736 :)
declare
- %test:assertEquals(' ')
+ %test:assertEquals('
hi
')
+function ser:serialize-html-5-with-indent() {
+ serialize(hi
,
+ map{ "method": "html", "version": "5.0", "indent": true() })
+};
+
+declare
+ %test:assertEquals('')
function ser:serialize-html-5-raw-text-elements-body() {
@@ -871,12 +875,11 @@ function ser:serialize-html-5-raw-text-elements-body() {
- => serialize($ser:opt-map-html5)
- => normalize-space()
+ => serialize($ser:opt-map-html5)
};
declare
- %test:assertEquals(' ')
+ %test:assertEquals('')
function ser:serialize-html-5-raw-text-elements-head() {
@@ -885,12 +888,11 @@ function ser:serialize-html-5-raw-text-elements-head() {
- => serialize($ser:opt-map-html5)
- => normalize-space()
+ => serialize($ser:opt-map-html5)
};
declare
- %test:assertEquals(' XML > JSON')
+ %test:assertEquals('XML > JSON')
function ser:serialize-html-5-needs-escape-elements() {
@@ -901,7 +903,6 @@ function ser:serialize-html-5-needs-escape-elements() {
=> serialize($ser:opt-map-html5)
- => normalize-space()
};
(: test for https://github.com/eXist-db/exist/issues/4702 :)