Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
48a842b5
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
48a842b5
编写于
3月 28, 2019
作者:
J
joehw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
Summary: Add JDK8207760.java jtreg test. Reviewed-by: lancea, dfuchs
上级
87c8c1a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
171 addition
and
0 deletion
+171
-0
test/javax/xml/jaxp/transform/8207760/JDK8207760.java
test/javax/xml/jaxp/transform/8207760/JDK8207760.java
+171
-0
未找到文件。
test/javax/xml/jaxp/transform/8207760/JDK8207760.java
0 → 100644
浏览文件 @
48a842b5
/*
* Copyright (c) 2018, 2019, 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.
*/
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.nio.charset.StandardCharsets
;
import
javax.xml.transform.Transformer
;
import
javax.xml.transform.TransformerException
;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.stream.StreamResult
;
import
javax.xml.transform.stream.StreamSource
;
import
org.testng.Assert
;
import
org.testng.annotations.Listeners
;
import
org.testng.annotations.Test
;
import
java.util.Random
;
import
javax.xml.transform.OutputKeys
;
import
org.testng.annotations.DataProvider
;
/*
* @test
* @run testng/othervm JDK8207760
* @summary Verifies that a surrogate pair at the edge of a buffer is properly handled
* @bug 8207760
*/
public
class
JDK8207760
{
final
String
xsl8207760
=
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
+
" <xsl:output omit-xml-declaration=\"yes\" indent=\"no\" />\n"
+
"\n"
+
" <xsl:template match=\"node()|@*\">\n"
+
" <xsl:copy>\n"
+
" <xsl:apply-templates select=\"node()|@*\" />\n"
+
" </xsl:copy>\n"
+
" </xsl:template>\n"
+
"</xsl:stylesheet>\n"
;
final
String
xsl8207760_2
=
"<xsl:stylesheet \n"
+
" version=\"1.0\" \n"
+
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
+
"\n"
+
" <xsl:output method=\"xml\" indent=\"no\" cdata-section-elements=\"source\"/>\n"
+
"\n"
+
" <xsl:template match=\"source\">\n"
+
" <xsl:copy>\n"
+
" <xsl:apply-templates select=\"node()\" />\n"
+
" </xsl:copy>\n"
+
" </xsl:template>\n"
+
"\n"
+
"</xsl:stylesheet>"
;
final
String
xsl8207760_3
=
"<xsl:stylesheet \n"
+
" version=\"1.0\" \n"
+
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
+
"\n"
+
" <xsl:output method=\"xml\" indent=\"no\" cdata-section-elements=\"source\"/>\n"
+
"\n"
+
" <xsl:template match=\"source\">\n"
+
" <xsl:copy>\n"
+
" <!-- Copy the attributes -->\n"
+
" <xsl:apply-templates select=\"@*\"/>\n"
+
" <!-- Convert the contained nodes (elements and text) into text -->\n"
+
" <xsl:variable name=\"subElementsText\">\n"
+
" <xsl:apply-templates select=\"node()\"/>\n"
+
" </xsl:variable>\n"
+
" <!-- Output the XML directive and the converted nodes -->\n"
+
" <xsl:value-of select=\"$subElementsText\"/>\n"
+
" </xsl:copy>\n"
+
" </xsl:template>\n"
+
"\n"
+
"</xsl:stylesheet>"
;
@DataProvider
(
name
=
"xsls"
)
public
Object
[][]
getDataBug8207760_cdata
()
{
return
new
Object
[][]{
{
xsl8207760_2
},
{
xsl8207760_3
},
};
}
/*
* @bug 8207760
* Verifies that a surrogate pair at the edge of a buffer is properly handled
* when serializing into a Character section.
*/
@Test
public
final
void
testBug8207760
()
throws
Exception
{
String
[]
xmls
=
prepareXML
(
false
);
Transformer
t
=
createTransformerFromInputstream
(
new
ByteArrayInputStream
(
xsl8207760
.
getBytes
(
StandardCharsets
.
UTF_8
)));
t
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
StandardCharsets
.
UTF_8
.
name
());
StringWriter
sw
=
new
StringWriter
();
t
.
transform
(
new
StreamSource
(
new
StringReader
(
xmls
[
0
])),
new
StreamResult
(
sw
));
Assert
.
assertEquals
(
sw
.
toString
().
replaceAll
(
System
.
lineSeparator
(),
"\n"
),
xmls
[
1
]);
}
/*
* @bug 8207760
* Verifies that a surrogate pair at the edge of a buffer is properly handled
* when serializing into a CDATA section.
*/
@Test
(
dataProvider
=
"xsls"
)
public
final
void
testBug8207760_cdata
(
String
xsl
)
throws
Exception
{
String
[]
xmls
=
prepareXML
(
true
);
Transformer
t
=
createTransformerFromInputstream
(
new
ByteArrayInputStream
(
xsl
.
getBytes
(
StandardCharsets
.
UTF_8
)));
t
.
setOutputProperty
(
OutputKeys
.
ENCODING
,
StandardCharsets
.
UTF_8
.
name
());
StringWriter
sw
=
new
StringWriter
();
t
.
transform
(
new
StreamSource
(
new
StringReader
(
xmls
[
0
])),
new
StreamResult
(
sw
));
Assert
.
assertEquals
(
sw
.
toString
().
replaceAll
(
System
.
lineSeparator
(),
"\n"
),
xmls
[
1
]);
}
private
String
[]
prepareXML
(
boolean
cdata
)
{
String
xml
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><source>"
;
if
(
cdata
)
{
xml
+=
"<![CDATA["
;
}
String
tail
=
"abc 123 </source>"
;
if
(
cdata
)
{
tail
=
"abc 123 ]]></source>"
;
}
String
temp
=
generateString
(
1023
);
xml
=
xml
+
temp
+
'\
uD83C
'
+
'\
uDF42
'
+
tail
;
//xml = xml + temp + tail;
String
expected
=
(!
cdata
)
?
"<source>"
+
temp
+
"🍂"
+
tail
:
xml
;
return
new
String
[]{
xml
,
expected
};
}
static
final
char
[]
CHARS
=
"abcdefghijklmnopqrstuvwxyz \n"
.
toCharArray
();
StringBuilder
sb
=
new
StringBuilder
(
1024
<<
4
);
Random
random
=
new
Random
();
private
String
generateString
(
int
size
)
{
sb
.
setLength
(
0
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
char
c
=
CHARS
[
random
.
nextInt
(
CHARS
.
length
)];
sb
.
append
(
c
);
}
return
sb
.
toString
();
}
private
Transformer
createTransformerFromInputstream
(
InputStream
xslStream
)
throws
TransformerException
{
return
TransformerFactory
.
newInstance
().
newTransformer
(
new
StreamSource
(
xslStream
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录