Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8265073: XML transformation and indentation when using xml:space
Reviewed-by: naoto, lancea, iris
  • Loading branch information
JoeWang-Java committed Jun 18, 2021
1 parent 60389ee commit 7e03cf2916a69f947c46ac85b222ee7a99f68ad8
@@ -53,7 +53,7 @@
* serializers (xml, html, text ...) that write output to a stream.
*
* @xsl.usage internal
* @LastModified: May 2021
* @LastModified: June 2021
*/
abstract public class ToStream extends SerializerBase {

@@ -1893,10 +1893,6 @@ else if (m_cdataTagOpen)
throw new SAXException(e);
}

// process the attributes now, because after this SAX call they might be gone
if (atts != null)
addAttributes(atts);

if (m_doIndent) {
m_ispreserveSpace = m_preserveSpaces.peekOrFalse();
m_preserveSpaces.push(m_ispreserveSpace);
@@ -1905,6 +1901,10 @@ else if (m_cdataTagOpen)
m_childNodeNum = 0;
}

// process the attributes now, because after this SAX call they might be gone
if (atts != null)
addAttributes(atts);

m_elemContext = m_elemContext.push(namespaceURI,localName,name);
m_isprevtext = false;

@@ -33,8 +33,6 @@
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -66,7 +64,7 @@

/*
* @test
* @bug 6439439 8087303 8174025 8223291 8249867 8261209 8260858
* @bug 6439439 8087303 8174025 8223291 8249867 8261209 8260858 8265073
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true -Djava.security.manager=allow common.prettyprint.PrettyPrintTest
* @run testng/othervm common.prettyprint.PrettyPrintTest
@@ -180,6 +178,54 @@
};
}

private final String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<a><b>element b</b><c>element c</c><d xml:space=\"preserve\">TRUE</d><e>test</e></a>";
private final String expected1 = "<a>\n"
+ " <b>element b</b>\n"
+ " <c>element c</c>\n"
+ " <d xml:space=\"preserve\">TRUE</d>\n"
+ " <e>test</e>\n"
+ "</a>\n";

private final String xml2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<l0><l1><l2 xml:space=\"preserve\">level 2</l2> level 1 <l2>level 2</l2></l1>"
+ "<l1 xml:space=\"preserve\"><l2>level 2</l2> level 1 <l2>level 2</l2></l1></l0>";
private final String expected2 = "<l0>\n"
+ " <l1>\n"
+ " <l2 xml:space=\"preserve\">level 2</l2>\n"
+ " level 1 \n"
+ " <l2>level 2</l2>\n"
+ " </l1>\n"
+ " <l1 xml:space=\"preserve\"><l2>level 2</l2> level 1 <l2>level 2</l2></l1>\n"
+ "</l0>\n";

/*
* Bug: 8265073
* source and expected output
*/
@DataProvider
public Object[][] preserveSpace() {
return new Object[][]{
{xml1, expected1},
{xml2, expected2},
};
}

/**
* Bug: 8265073
* Verifies that the scope of the preserve attribute is applied properly
* within the relevant elements.
* @param xml the source
* @param expected the expected result
* @throws Exception if the assertion fails or an error occurs in the
* transform process
*/
@Test(dataProvider = "preserveSpace")
public void test(String xml, String expected) throws Exception {
String result = transform(null, xml, true, true, false, false, false);
Assert.assertEquals(result.replaceAll("\r\n", "\n"), expected);
}

/*
* Bug: 8260858
* Verifies the use of the new property "xsltcIsStandalone" and the

1 comment on commit 7e03cf2

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 7e03cf2 Jun 18, 2021

Please sign in to comment.