Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void endDocument() throws TransformerException {
@Override
public void endDocumentType() throws TransformerException {
super.endDocumentType();
super.characters("\n");
indent();
sameline = false;
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setUp() throws Exception {

@Test
public void testAttributeWithBooleanValue() throws Exception {
final String expected = "<!DOCTYPE html>\n<input checked>";
final String expected = "<!DOCTYPE html><input checked>";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be useful to have an other test with the \n still there, to show the (non?) effect of the changes?

final QName elQName = new QName("input");
writer.startElement(elQName);
writer.attribute("checked", "checked");
Expand All @@ -54,7 +54,7 @@ public void testAttributeWithBooleanValue() throws Exception {

@Test
public void testAttributeWithNonBooleanValue() throws Exception {
final String expected = "<!DOCTYPE html>\n<input name=\"name\">";
final String expected = "<!DOCTYPE html><input name=\"name\">";
final QName elQName = new QName("input");
writer.startElement(elQName);
writer.attribute("name", "name");
Expand All @@ -66,7 +66,7 @@ public void testAttributeWithNonBooleanValue() throws Exception {

@Test
public void testAttributeQNameWithBooleanValue() throws Exception {
final String expected = "<!DOCTYPE html>\n<input checked>";
final String expected = "<!DOCTYPE html><input checked>";
final QName elQName = new QName("input");
final QName attrQName = new QName("checked");
writer.startElement(elQName);
Expand All @@ -79,7 +79,7 @@ public void testAttributeQNameWithBooleanValue() throws Exception {

@Test
public void testAttributeQNameWithNonBooleanValue() throws Exception {
final String expected = "<!DOCTYPE html>\n<input name=\"name\">";
final String expected = "<!DOCTYPE html><input name=\"name\">";
final QName elQName = new QName("input");
final QName attrQName = new QName("name");
writer.startElement(elQName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,7 @@ public class SerializationTest {

private static final String XML_WITH_DOCTYPE =
"<!DOCTYPE bookmap PUBLIC \"-//OASIS//DTD DITA BookMap//EN\" \"bookmap.dtd\">\n" +
"<bookmap id=\"bookmap-1\"/>";
"<bookmap id=\"bookmap-1\">\n asdf\n </bookmap>";

private static final XmldbURI TEST_XML_DOC_WITH_XMLDECL_URI = XmldbURI.create("test-with-xmldecl.xml");

Expand All @@ -118,7 +119,7 @@ public static java.util.Collection<Object[]> data() {

private Collection testCollection;

private final String getBaseUri() {
private String getBaseUri() {
return baseUri.replace(PORT_PLACEHOLDER, Integer.toString(existWebServer.getPort()));
}

Expand Down Expand Up @@ -186,7 +187,7 @@ public void getDocTypeNo() throws XMLDBException {
try {
final Resource res = testCollection.getResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString());
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, "no");
assertEquals("<bookmap id=\"bookmap-1\"/>", res.getContent());
assertEquals("<bookmap id=\"bookmap-1\">\n asdf\n </bookmap>", res.getContent());
} finally {
if (prevOutputDocType != null) {
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, prevOutputDocType);
Expand Down Expand Up @@ -271,7 +272,11 @@ public void setUp() throws XMLDBException {
final XMLResource res2 = testCollection.createResource(TEST_XML_DOC_WITH_XMLDECL_URI.lastSegmentString(), XMLResource.class);
res2.setContent(XML_WITH_XMLDECL);
testCollection.storeResource(res2);
}

// FIXME (JL): local and remote collections apparently have different output properties set
// local collections have INDENT set to "yes" whereas remote collections have "no" by default
testCollection.setProperty(INDENT, "yes");
}

@After
public void tearDown() throws XMLDBException {
Expand Down
33 changes: 17 additions & 16 deletions exist-core/src/test/xquery/xquery3/serialize.xql
Original file line number Diff line number Diff line change
Expand Up @@ -847,36 +847,39 @@ function ser:serialize-xml-134() {
};

declare
%test:assertEquals('<!DOCTYPE html> <option selected></option>')
%test:assertEquals('<!DOCTYPE html><option selected></option>')
function ser:serialize-html-5-boolean-attribute-names() {
<option selected="selected"/>
=> serialize($ser:opt-map-html5)
=> normalize-space()
serialize(<option selected="selected"/>, $ser:opt-map-html5)
};

declare
%test:assertEquals('<!DOCTYPE html> <br>')
%test:assertEquals('<!DOCTYPE html><br>')
function ser:serialize-html-5-empty-tags() {
<br/>
=> serialize($ser:opt-map-html5)
=> normalize-space()
serialize(<br/>, $ser:opt-map-html5)
};

(: test for https://github.com/eXist-db/exist/issues/4736 :)
declare
%test:assertEquals('<!DOCTYPE html> <html><body><style>ul > li { color:red; }</style><script>if (a < b) foo()</script></body></html>')
%test:assertEquals('<!DOCTYPE html>&#10;<html>&#10; <body>&#10; <p>hi</p>&#10; </body>&#10;</html>')
function ser:serialize-html-5-with-indent() {
serialize(<html><body><p>hi</p></body></html>,
map{ "method": "html", "version": "5.0", "indent": true() })
};

declare
%test:assertEquals('<!DOCTYPE html><html><body><style>ul > li { color:red; }</style><script>if (a < b) foo()</script></body></html>')
function ser:serialize-html-5-raw-text-elements-body() {
<html>
<body>
<style><![CDATA[ul > li { color:red; }]]></style>
<script><![CDATA[if (a < b) foo()]]></script>
</body>
</html>
=> serialize($ser:opt-map-html5)
=> normalize-space()
=> serialize($ser:opt-map-html5)
};

declare
%test:assertEquals('<!DOCTYPE html> <html><head><style>ul > li { color:red; }</style><script>if (a < b) foo()</script></head><body></body></html>')
%test:assertEquals('<!DOCTYPE html><html><head><style>ul > li { color:red; }</style><script>if (a < b) foo()</script></head><body></body></html>')
function ser:serialize-html-5-raw-text-elements-head() {
<html>
<head>
Expand All @@ -885,12 +888,11 @@ function ser:serialize-html-5-raw-text-elements-head() {
</head>
<body></body>
</html>
=> serialize($ser:opt-map-html5)
=> normalize-space()
=> serialize($ser:opt-map-html5)
};

declare
%test:assertEquals('<!DOCTYPE html> <html><head><title>XML &amp;gt; JSON</title></head><body><textarea>if (a &amp;lt; b) foo()</textarea></body></html>')
%test:assertEquals('<!DOCTYPE html><html><head><title>XML &amp;gt; JSON</title></head><body><textarea>if (a &amp;lt; b) foo()</textarea></body></html>')
function ser:serialize-html-5-needs-escape-elements() {
<html>
<head>
Expand All @@ -901,7 +903,6 @@ function ser:serialize-html-5-needs-escape-elements() {
</body>
</html>
=> serialize($ser:opt-map-html5)
=> normalize-space()
};

(: test for https://github.com/eXist-db/exist/issues/4702 :)
Expand Down