-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8268457: XML Transformer outputs Unicode supplementary character incorrectly to HTML #4474
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package transform; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.FileReader; | ||
import java.io.InputStream; | ||
|
||
import javax.xml.parsers.SAXParser; | ||
import javax.xml.parsers.SAXParserFactory; | ||
import javax.xml.transform.Result; | ||
import javax.xml.transform.Source; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.stream.StreamResult; | ||
import javax.xml.transform.stream.StreamSource; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
import static jaxp.library.JAXPTestUtilities.compareWithGold; | ||
import static jaxp.library.JAXPTestUtilities.compareStringWithGold; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
/* | ||
* @test | ||
* @bug 8268457 | ||
* @library /javax/xml/jaxp/libs | ||
* @run testng transform.SurrogateTest | ||
* @summary XML Transformer outputs Unicode supplementary character incorrectly to HTML | ||
*/ | ||
@Listeners({jaxp.library.FilePolicy.class}) | ||
public class SurrogateTest { | ||
|
||
final static String TEST_SRC = System.getProperty("test.src", "."); | ||
|
||
@Test | ||
public void toHTMLTest() throws Exception { | ||
String out = "SurrogateTest1out.html"; | ||
String expected = TEST_SRC + File.separator + "SurrogateTest1.html"; | ||
String xsl = TEST_SRC + File.separator + "SurrogateTest1.xsl"; | ||
|
||
try (FileInputStream tFis = new FileInputStream(xsl); | ||
InputStream fis = this.getClass().getResourceAsStream("SurrogateTest1.xml"); | ||
FileOutputStream fos = new FileOutputStream(out)) { | ||
|
||
Source tSrc = new StreamSource(tFis); | ||
TransformerFactory tf = TransformerFactory.newInstance(); | ||
Transformer t = tf.newTransformer(tSrc); | ||
t.setOutputProperty("method", "html"); | ||
|
||
Source src = new StreamSource(fis); | ||
Result res = new StreamResult(fos); | ||
t.transform(src, res); | ||
} | ||
compareWithGold(expected, out); | ||
} | ||
|
||
@Test | ||
public void handlerTest() throws Exception { | ||
File xmlFile = new File(TEST_SRC, "SurrogateTest2.xml"); | ||
SAXParserFactory spf = SAXParserFactory.newInstance(); | ||
spf.setNamespaceAware(true); | ||
SAXParser sp = spf.newSAXParser(); | ||
TestHandler th = new TestHandler(); | ||
sp.parse(xmlFile, th); | ||
compareStringWithGold(TEST_SRC + File.separator + "SurrogateTest2.txt", th.sb.toString()); | ||
} | ||
|
||
private static class TestHandler extends DefaultHandler { | ||
private StringBuilder sb = new StringBuilder(); | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { | ||
sb.append( localName + "@attr:" + attributes.getValue("attr") + '\n'); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
</head> | ||
<body> | ||
<form> | ||
<input id="tag1" value="𠮟"> | ||
</form> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
<tag1>𠮟</tag1> | ||
</root> |
26 changes: 26 additions & 0 deletions
26
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | ||
<xsl:output doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" | ||
doctype-system="http://www.w3.org/TR/html4/loose.dtd" | ||
encoding="UTF-8" indent="yes" method="html" omit-xml-declaration="yes"/> | ||
<xsl:template match="/"> | ||
<html> | ||
<head> | ||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
</head> | ||
<body> | ||
<xsl:for-each select="root"> | ||
<form> | ||
<xsl:for-each select="tag1"> | ||
<input id="tag1"> | ||
<xsl:attribute name="value"> | ||
<xsl:value-of select="."/> | ||
</xsl:attribute> | ||
</input> | ||
</xsl:for-each> | ||
</form> | ||
</xsl:for-each> | ||
</body> | ||
</html> | ||
</xsl:template> | ||
</xsl:stylesheet> |
4 changes: 4 additions & 0 deletions
4
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
root@attr:null | ||
tag1@attr:𠮟 | ||
tag2@attr:𠀋 | ||
tag3@attr:𣱿 |
6 changes: 6 additions & 0 deletions
6
test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
<tag1 attr="𠮟"/> | ||
<tag2 attr="𠀋"/> | ||
<tag3 attr="𣱿"/> | ||
</root> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting removing the entire comment-out block if it is not needed (and confusing), but I will defer the decision to Joe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It's very obsolete. The comment-out block from line 1445 to 1454 can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mistaken. I deleted the entire comment.