Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ab99ed

Browse files
committed
8268457: XML Transformer outputs Unicode supplementary character incorrectly to HTML
Backport-of: 83bce94cc8a7fb45b0604598411fbecc62000dfd
1 parenta834b58 commit0ab99ed

File tree

7 files changed

+173
-26
lines changed

7 files changed

+173
-26
lines changed

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014,2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014,2021, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -41,7 +41,7 @@
4141
* because it is used from another package.
4242
*
4343
* @xsl.usage internal
44-
* @LastModified:Aug 2019
44+
* @LastModified:June 2021
4545
*/
4646
publicfinalclassToHTMLStreamextendsToStream
4747
{
@@ -1441,32 +1441,23 @@ else if (
14411441
}
14421442
}
14431443
}
1444-
1445-
// The next is kind of a hack to keep from escaping in the case
1446-
// of Shift_JIS and the like.
1447-
1448-
/*
1449-
else if ((ch < m_maxCharacter) && (m_maxCharacter == 0xFFFF)
1450-
&& (ch != 160))
1451-
{
1452-
writer.write(ch); // no escaping in this case
1453-
}
1454-
else
1455-
*/
1456-
StringoutputStringForChar =m_charInfo.getOutputStringForChar(ch);
1457-
if (null !=outputStringForChar)
1458-
{
1459-
writer.write(outputStringForChar);
1460-
}
1461-
elseif (escapingNotNeeded(ch))
1462-
{
1463-
writer.write(ch);// no escaping in this case
1464-
}
14651444
else
14661445
{
1467-
writer.write("&#");
1468-
writer.write(Integer.toString(ch));
1469-
writer.write(';');
1446+
StringoutputStringForChar =m_charInfo.getOutputStringForChar(ch);
1447+
if (null !=outputStringForChar)
1448+
{
1449+
writer.write(outputStringForChar);
1450+
}
1451+
elseif (escapingNotNeeded(ch))
1452+
{
1453+
writer.write(ch);// no escaping in this case
1454+
}
1455+
else
1456+
{
1457+
writer.write("&#");
1458+
writer.write(Integer.toString(ch));
1459+
writer.write(';');
1460+
}
14701461
}
14711462
}
14721463
cleanStart =i +1;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
packagetransform;
25+
26+
importjava.io.File;
27+
importjava.io.FileInputStream;
28+
importjava.io.FileOutputStream;
29+
importjava.io.FileReader;
30+
importjava.io.InputStream;
31+
32+
importjavax.xml.parsers.SAXParser;
33+
importjavax.xml.parsers.SAXParserFactory;
34+
importjavax.xml.transform.Result;
35+
importjavax.xml.transform.Source;
36+
importjavax.xml.transform.Transformer;
37+
importjavax.xml.transform.TransformerFactory;
38+
importjavax.xml.transform.stream.StreamResult;
39+
importjavax.xml.transform.stream.StreamSource;
40+
41+
importorg.xml.sax.Attributes;
42+
importorg.xml.sax.SAXException;
43+
importorg.xml.sax.helpers.DefaultHandler;
44+
45+
importstaticjaxp.library.JAXPTestUtilities.compareWithGold;
46+
importstaticjaxp.library.JAXPTestUtilities.compareStringWithGold;
47+
importorg.testng.Assert;
48+
importorg.testng.annotations.Listeners;
49+
importorg.testng.annotations.Test;
50+
51+
/*
52+
* @test
53+
* @bug 8268457
54+
* @library /javax/xml/jaxp/libs
55+
* @run testng transform.SurrogateTest
56+
* @summary XML Transformer outputs Unicode supplementary character incorrectly to HTML
57+
*/
58+
@Listeners({jaxp.library.FilePolicy.class})
59+
publicclassSurrogateTest {
60+
61+
finalstaticStringTEST_SRC =System.getProperty("test.src",".");
62+
63+
@Test
64+
publicvoidtoHTMLTest()throwsException {
65+
Stringout ="SurrogateTest1out.html";
66+
Stringexpected =TEST_SRC +File.separator +"SurrogateTest1.html";
67+
Stringxsl =TEST_SRC +File.separator +"SurrogateTest1.xsl";
68+
69+
try (FileInputStreamtFis =newFileInputStream(xsl);
70+
InputStreamfis =this.getClass().getResourceAsStream("SurrogateTest1.xml");
71+
FileOutputStreamfos =newFileOutputStream(out)) {
72+
73+
SourcetSrc =newStreamSource(tFis);
74+
TransformerFactorytf =TransformerFactory.newInstance();
75+
Transformert =tf.newTransformer(tSrc);
76+
t.setOutputProperty("method","html");
77+
78+
Sourcesrc =newStreamSource(fis);
79+
Resultres =newStreamResult(fos);
80+
t.transform(src,res);
81+
}
82+
compareWithGold(expected,out);
83+
}
84+
85+
@Test
86+
publicvoidhandlerTest()throwsException {
87+
FilexmlFile =newFile(TEST_SRC,"SurrogateTest2.xml");
88+
SAXParserFactoryspf =SAXParserFactory.newInstance();
89+
spf.setNamespaceAware(true);
90+
SAXParsersp =spf.newSAXParser();
91+
TestHandlerth =newTestHandler();
92+
sp.parse(xmlFile,th);
93+
compareStringWithGold(TEST_SRC +File.separator +"SurrogateTest2.txt",th.sb.toString());
94+
}
95+
96+
privatestaticclassTestHandlerextendsDefaultHandler {
97+
privateStringBuildersb =newStringBuilder();
98+
99+
@Override
100+
publicvoidstartElement(Stringuri,StringlocalName,StringqName,Attributesattributes)throwsSAXException {
101+
sb.append(localName +"@attr:" +attributes.getValue("attr") +'\n');
102+
}
103+
}
104+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html>
3+
<head>
4+
<METAhttp-equiv="Content-Type"content="text/html; charset=UTF-8">
5+
<METAhttp-equiv="Content-Type"content="text/html; charset=UTF-8">
6+
</head>
7+
<body>
8+
<form>
9+
<inputid="tag1"value="𠮟">
10+
</form>
11+
</body>
12+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<tag1>𠮟</tag1>
4+
</root>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0">
3+
<xsl:outputdoctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
4+
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
5+
encoding="UTF-8"indent="yes"method="html"omit-xml-declaration="yes"/>
6+
<xsl:templatematch="/">
7+
<html>
8+
<head>
9+
<METAhttp-equiv="Content-Type"content="text/html; charset=UTF-8"/>
10+
</head>
11+
<body>
12+
<xsl:for-eachselect="root">
13+
<form>
14+
<xsl:for-eachselect="tag1">
15+
<inputid="tag1">
16+
<xsl:attributename="value">
17+
<xsl:value-ofselect="."/>
18+
</xsl:attribute>
19+
</input>
20+
</xsl:for-each>
21+
</form>
22+
</xsl:for-each>
23+
</body>
24+
</html>
25+
</xsl:template>
26+
</xsl:stylesheet>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root@attr:null
2+
tag1@attr:𠮟
3+
tag2@attr:𠀋
4+
tag3@attr:𣱿
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<tag1attr="𠮟"/>
4+
<tag2attr="𠀋"/>
5+
<tag3attr="𣱿"/>
6+
</root>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp