Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 7e03cf2

Browse files
committed
8265073: XML transformation and indentation when using xml:space
Reviewed-by: naoto, lancea, iris
1 parent 60389ee commit 7e03cf2

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* serializers (xml, html, text ...) that write output to a stream.
5454
*
5555
* @xsl.usage internal
56-
* @LastModified: May 2021
56+
* @LastModified: June 2021
5757
*/
5858
abstract public class ToStream extends SerializerBase {
5959

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

1896-
// process the attributes now, because after this SAX call they might be gone
1897-
if (atts != null)
1898-
addAttributes(atts);
1899-
19001896
if (m_doIndent) {
19011897
m_ispreserveSpace = m_preserveSpaces.peekOrFalse();
19021898
m_preserveSpaces.push(m_ispreserveSpace);
@@ -1905,6 +1901,10 @@ else if (m_cdataTagOpen)
19051901
m_childNodeNum = 0;
19061902
}
19071903

1904+
// process the attributes now, because after this SAX call they might be gone
1905+
if (atts != null)
1906+
addAttributes(atts);
1907+
19081908
m_elemContext = m_elemContext.push(namespaceURI,localName,name);
19091909
m_isprevtext = false;
19101910

test/jaxp/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.io.InputStream;
3434
import java.io.StringReader;
3535
import java.io.StringWriter;
36-
import java.nio.file.Files;
37-
import java.nio.file.Paths;
3836

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

6765
/*
6866
* @test
69-
* @bug 6439439 8087303 8174025 8223291 8249867 8261209 8260858
67+
* @bug 6439439 8087303 8174025 8223291 8249867 8261209 8260858 8265073
7068
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
7169
* @run testng/othervm -DrunSecMngr=true -Djava.security.manager=allow common.prettyprint.PrettyPrintTest
7270
* @run testng/othervm common.prettyprint.PrettyPrintTest
@@ -180,6 +178,54 @@ Object[][] getSystemProperty() throws Exception {
180178
};
181179
}
182180

181+
private final String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
182+
+ "<a><b>element b</b><c>element c</c><d xml:space=\"preserve\">TRUE</d><e>test</e></a>";
183+
private final String expected1 = "<a>\n"
184+
+ " <b>element b</b>\n"
185+
+ " <c>element c</c>\n"
186+
+ " <d xml:space=\"preserve\">TRUE</d>\n"
187+
+ " <e>test</e>\n"
188+
+ "</a>\n";
189+
190+
private final String xml2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
191+
+ "<l0><l1><l2 xml:space=\"preserve\">level 2</l2> level 1 <l2>level 2</l2></l1>"
192+
+ "<l1 xml:space=\"preserve\"><l2>level 2</l2> level 1 <l2>level 2</l2></l1></l0>";
193+
private final String expected2 = "<l0>\n"
194+
+ " <l1>\n"
195+
+ " <l2 xml:space=\"preserve\">level 2</l2>\n"
196+
+ " level 1 \n"
197+
+ " <l2>level 2</l2>\n"
198+
+ " </l1>\n"
199+
+ " <l1 xml:space=\"preserve\"><l2>level 2</l2> level 1 <l2>level 2</l2></l1>\n"
200+
+ "</l0>\n";
201+
202+
/*
203+
* Bug: 8265073
204+
* source and expected output
205+
*/
206+
@DataProvider
207+
public Object[][] preserveSpace() {
208+
return new Object[][]{
209+
{xml1, expected1},
210+
{xml2, expected2},
211+
};
212+
}
213+
214+
/**
215+
* Bug: 8265073
216+
* Verifies that the scope of the preserve attribute is applied properly
217+
* within the relevant elements.
218+
* @param xml the source
219+
* @param expected the expected result
220+
* @throws Exception if the assertion fails or an error occurs in the
221+
* transform process
222+
*/
223+
@Test(dataProvider = "preserveSpace")
224+
public void test(String xml, String expected) throws Exception {
225+
String result = transform(null, xml, true, true, false, false, false);
226+
Assert.assertEquals(result.replaceAll("\r\n", "\n"), expected);
227+
}
228+
183229
/*
184230
* Bug: 8260858
185231
* Verifies the use of the new property "xsltcIsStandalone" and the

0 commit comments

Comments
 (0)