diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java index 042d8bc686b..ff838e30fe7 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -41,7 +41,7 @@ * because it is used from another package. * * @xsl.usage internal - * @LastModified: Aug 2019 + * @LastModified: June 2021 */ public final class ToHTMLStream extends ToStream { @@ -1441,32 +1441,23 @@ else if ( } } } - - // The next is kind of a hack to keep from escaping in the case - // of Shift_JIS and the like. - - /* - else if ((ch < m_maxCharacter) && (m_maxCharacter == 0xFFFF) - && (ch != 160)) - { - writer.write(ch); // no escaping in this case - } - else - */ - String outputStringForChar = m_charInfo.getOutputStringForChar(ch); - if (null != outputStringForChar) - { - writer.write(outputStringForChar); - } - else if (escapingNotNeeded(ch)) - { - writer.write(ch); // no escaping in this case - } else { - writer.write("&#"); - writer.write(Integer.toString(ch)); - writer.write(';'); + String outputStringForChar = m_charInfo.getOutputStringForChar(ch); + if (null != outputStringForChar) + { + writer.write(outputStringForChar); + } + else if (escapingNotNeeded(ch)) + { + writer.write(ch); // no escaping in this case + } + else + { + writer.write("&#"); + writer.write(Integer.toString(ch)); + writer.write(';'); + } } } cleanStart = i + 1; diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest.java b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest.java new file mode 100644 index 00000000000..9eb358fef71 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest.java @@ -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'); + } + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.html b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.html new file mode 100644 index 00000000000..e2db93fa3bc --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.html @@ -0,0 +1,12 @@ + + + + + + + +
+ +
+ + diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xml b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xml new file mode 100644 index 00000000000..bb346086b05 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xml @@ -0,0 +1,4 @@ + + + 𠮟 + diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xsl b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xsl new file mode 100644 index 00000000000..b7a64d5170b --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest1.xsl @@ -0,0 +1,26 @@ + + + + + + + + + + +
+ + + + + + + +
+
+ + +
+
diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.txt b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.txt new file mode 100644 index 00000000000..0e3ce0062c7 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.txt @@ -0,0 +1,4 @@ +root@attr:null +tag1@attr:𠮟 +tag2@attr:𠀋 +tag3@attr:𣱿 diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.xml b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.xml new file mode 100644 index 00000000000..3f91e3c82ae --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/SurrogateTest2.xml @@ -0,0 +1,6 @@ + + + + + +