Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
38837edd
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
38837edd
编写于
7月 27, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HtmlUtils properly escapes single quotes as well
上级
9347ac35
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
21 deletion
+24
-21
org.springframework.web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java
...ringframework/web/util/HtmlCharacterEntityReferences.java
+8
-8
org.springframework.web/src/main/resources/org/springframework/web/util/HtmlCharacterEntityReferences.properties
...amework/web/util/HtmlCharacterEntityReferences.properties
+1
-4
org.springframework.web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java
...est/java/org/springframework/web/util/HtmlUtilsTests.java
+15
-9
未找到文件。
org.springframework.web/src/main/java/org/springframework/web/util/HtmlCharacterEntityReferences.java
浏览文件 @
38837edd
/*
* Copyright 2002-20
05
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -38,6 +38,8 @@ import org.springframework.util.Assert;
*/
class
HtmlCharacterEntityReferences
{
private
static
final
String
PROPERTIES_FILE
=
"HtmlCharacterEntityReferences.properties"
;
static
final
char
REFERENCE_START
=
'&'
;
static
final
String
DECIMAL_REFERENCE_START
=
"&#"
;
...
...
@@ -49,12 +51,9 @@ class HtmlCharacterEntityReferences {
static
final
char
CHAR_NULL
=
(
char
)
-
1
;
private
static
final
String
PROPERTIES_FILE
=
"HtmlCharacterEntityReferences.properties"
;
private
final
String
[]
characterToEntityReferenceMap
=
new
String
[
3000
];
private
final
Map
entityReferenceToCharacterMap
=
new
HashMap
(
252
);
private
final
Map
<
String
,
Character
>
entityReferenceToCharacterMap
=
new
HashMap
<
String
,
Character
>
(
252
);
/**
...
...
@@ -63,7 +62,7 @@ class HtmlCharacterEntityReferences {
public
HtmlCharacterEntityReferences
()
{
Properties
entityReferences
=
new
Properties
();
// Load refe
ence definition file.
// Load refe
rence definition file
InputStream
is
=
HtmlCharacterEntityReferences
.
class
.
getResourceAsStream
(
PROPERTIES_FILE
);
if
(
is
==
null
)
{
throw
new
IllegalStateException
(
...
...
@@ -82,7 +81,7 @@ class HtmlCharacterEntityReferences {
"Failed to parse reference definition file [HtmlCharacterEntityReferences.properties]: "
+
ex
.
getMessage
());
}
// Parse reference definition proper
ites.
// Parse reference definition proper
ties
Enumeration
keys
=
entityReferences
.
propertyNames
();
while
(
keys
.
hasMoreElements
())
{
String
key
=
(
String
)
keys
.
nextElement
();
...
...
@@ -96,6 +95,7 @@ class HtmlCharacterEntityReferences {
}
}
/**
* Return the number of supported entity references.
*/
...
...
@@ -128,7 +128,7 @@ class HtmlCharacterEntityReferences {
* Return the char mapped to the given entityReference or -1.
*/
public
char
convertToCharacter
(
String
entityReference
)
{
Character
referredCharacter
=
(
Character
)
this
.
entityReferenceToCharacterMap
.
get
(
entityReference
);
Character
referredCharacter
=
this
.
entityReferenceToCharacterMap
.
get
(
entityReference
);
if
(
referredCharacter
!=
null
)
{
return
referredCharacter
.
charValue
();
}
...
...
org.springframework.web/src/main/resources/org/springframework/web/util/HtmlCharacterEntityReferences.properties
浏览文件 @
38837edd
...
...
@@ -2,7 +2,6 @@
# A complete description of the HTML 4.0 character set can be found at:
# http://www.w3.org/TR/html4/charset.html
# Character entity references for ISO 8859-1 characters
160
=
nbsp
...
...
@@ -102,7 +101,6 @@
254
=
thorn
255
=
yuml
# Character entity references for symbols, mathematical symbols, and Greek letters
402
=
fnof
...
...
@@ -230,11 +228,11 @@
9829
=
hearts
9830
=
diams
# Character entity references for markup-significant and internationalization characters
34
=
quot
38
=
amp
39
=
#39
60 = lt
62
=
gt
338
=
OElig
...
...
@@ -265,4 +263,3 @@
8249
=
lsaquo
8250
=
rsaquo
8364
=
euro
org.springframework.web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java
浏览文件 @
38837edd
/*
* Copyright 2002-20
07
the original author or authors.
* Copyright 2002-20
11
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,31 +16,36 @@
package
org.springframework.web.util
;
import
junit.framework.TestCase
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Alef Arendsen
* @author Martin Kersten
* @author Rick Evans
*/
public
class
HtmlUtilsTests
extends
TestCase
{
public
class
HtmlUtilsTests
{
@Test
public
void
testHtmlEscape
()
{
String
unescaped
=
"\"This is a quote"
;
String
unescaped
=
"\"This is a quote
'
"
;
String
escaped
=
HtmlUtils
.
htmlEscape
(
unescaped
);
assertEquals
(
""This is a quote"
,
escaped
);
assertEquals
(
""This is a quote
'
"
,
escaped
);
escaped
=
HtmlUtils
.
htmlEscapeDecimal
(
unescaped
);
assertEquals
(
""This is a quote"
,
escaped
);
assertEquals
(
""This is a quote
'
"
,
escaped
);
escaped
=
HtmlUtils
.
htmlEscapeHex
(
unescaped
);
assertEquals
(
""This is a quote"
,
escaped
);
assertEquals
(
""This is a quote
'
"
,
escaped
);
}
@Test
public
void
testHtmlUnescape
()
{
String
escaped
=
""This is a quote"
;
String
escaped
=
""This is a quote
'
"
;
String
unescaped
=
HtmlUtils
.
htmlUnescape
(
escaped
);
assertEquals
(
unescaped
,
"\"This is a quote"
);
assertEquals
(
unescaped
,
"\"This is a quote
'
"
);
}
@Test
public
void
testEncodeIntoHtmlCharacterSet
()
{
assertNull
(
"A null string should be converted to a null string"
,
HtmlUtils
.
htmlEscape
(
null
));
...
...
@@ -66,6 +71,7 @@ public class HtmlUtilsTests extends TestCase {
"ϑ"
,
HtmlUtils
.
htmlEscapeDecimal
(
""
+
(
char
)
977
));
}
@Test
public
void
testDecodeFromHtmlCharacterSet
()
{
assertNull
(
"A null string should be converted to a null string"
,
HtmlUtils
.
htmlUnescape
(
null
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录