Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
92795f46
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,体验更适合开发者的 AI 搜索 >>
提交
92795f46
编写于
9月 25, 2013
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish
Issue: SPR-10539
上级
2dd44801
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
24 deletion
+37
-24
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
...g/springframework/web/util/HierarchicalUriComponents.java
+6
-8
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
...va/org/springframework/web/util/UriComponentsBuilder.java
+2
-2
spring-web/src/main/java/org/springframework/web/util/UriUtils.java
.../src/main/java/org/springframework/web/util/UriUtils.java
+1
-1
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
...g/springframework/web/util/UriComponentsBuilderTests.java
+4
-5
spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java
...java/org/springframework/web/util/UriComponentsTests.java
+24
-8
未找到文件。
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
浏览文件 @
92795f46
...
...
@@ -182,12 +182,7 @@ final class HierarchicalUriComponents extends UriComponents {
}
String
encodedScheme
=
encodeUriComponent
(
this
.
getScheme
(),
encoding
,
Type
.
SCHEME
);
String
encodedUserInfo
=
encodeUriComponent
(
this
.
userInfo
,
encoding
,
Type
.
USER_INFO
);
String
encodedHost
;
if
(
StringUtils
.
hasLength
(
this
.
host
)
&&
this
.
host
.
startsWith
(
"["
))
{
encodedHost
=
encodeUriComponent
(
this
.
host
,
encoding
,
Type
.
HOST_IPV6
);
}
else
{
encodedHost
=
encodeUriComponent
(
this
.
host
,
encoding
,
Type
.
HOST
);
}
String
encodedHost
=
encodeUriComponent
(
this
.
host
,
encoding
,
getHostType
());
PathComponent
encodedPath
=
this
.
path
.
encode
(
encoding
);
MultiValueMap
<
String
,
String
>
encodedQueryParams
=
...
...
@@ -246,6 +241,9 @@ final class HierarchicalUriComponents extends UriComponents {
return
bos
.
toByteArray
();
}
private
Type
getHostType
()
{
return
((
this
.
host
!=
null
)
&&
this
.
host
.
startsWith
(
"["
))
?
Type
.
HOST_IPV6
:
Type
.
HOST_IPV4
;
}
// verifying
...
...
@@ -260,7 +258,7 @@ final class HierarchicalUriComponents extends UriComponents {
}
verifyUriComponent
(
getScheme
(),
Type
.
SCHEME
);
verifyUriComponent
(
userInfo
,
Type
.
USER_INFO
);
verifyUriComponent
(
host
,
Type
.
HOST
);
verifyUriComponent
(
host
,
getHostType
()
);
this
.
path
.
verify
();
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
queryParams
.
entrySet
())
{
verifyUriComponent
(
entry
.
getKey
(),
Type
.
QUERY_PARAM
);
...
...
@@ -468,7 +466,7 @@ final class HierarchicalUriComponents extends UriComponents {
return
isUnreserved
(
c
)
||
isSubDelimiter
(
c
)
||
':'
==
c
;
}
},
HOST
{
HOST
_IPV4
{
@Override
public
boolean
isAllowed
(
int
c
)
{
return
isUnreserved
(
c
)
||
isSubDelimiter
(
c
);
...
...
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
浏览文件 @
92795f46
...
...
@@ -64,11 +64,11 @@ public class UriComponentsBuilder {
private
static
final
String
USERINFO_PATTERN
=
"([^@/]*)"
;
private
static
final
String
HOST_IP
v
4_PATTERN
=
"[^\\[/?#:]*"
;
private
static
final
String
HOST_IP
V
4_PATTERN
=
"[^\\[/?#:]*"
;
private
static
final
String
HOST_IPV6_PATTERN
=
"\\[[\\p{XDigit}\\:\\.]*[%\\p{Alnum}]*\\]"
;
private
static
final
String
HOST_PATTERN
=
"("
+
HOST_IPV6_PATTERN
+
"|"
+
HOST_IPv
4_PATTERN
+
")"
;
private
static
final
String
HOST_PATTERN
=
"("
+
HOST_IPV6_PATTERN
+
"|"
+
HOST_IPV
4_PATTERN
+
")"
;
private
static
final
String
PORT_PATTERN
=
"(\\d*)"
;
...
...
spring-web/src/main/java/org/springframework/web/util/UriUtils.java
浏览文件 @
92795f46
...
...
@@ -254,7 +254,7 @@ public abstract class UriUtils {
*/
public
static
String
encodeHost
(
String
host
,
String
encoding
)
throws
UnsupportedEncodingException
{
return
HierarchicalUriComponents
.
encodeUriComponent
(
host
,
encoding
,
HierarchicalUriComponents
.
Type
.
HOST
);
.
encodeUriComponent
(
host
,
encoding
,
HierarchicalUriComponents
.
Type
.
HOST
_IPV4
);
}
/**
...
...
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java
浏览文件 @
92795f46
...
...
@@ -173,8 +173,7 @@ public class UriComponentsBuilderTests {
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
fromHttpUrlStringInvalidIPv6Host
()
throws
URISyntaxException
{
UriComponents
result
=
UriComponentsBuilder
.
fromHttpUrl
(
"http://[1abc:2abc:3abc::5ABC:6abc:8080/resource"
).
build
().
encode
();
UriComponentsBuilder
.
fromHttpUrl
(
"http://[1abc:2abc:3abc::5ABC:6abc:8080/resource"
).
build
().
encode
();
}
// SPR-10539
...
...
@@ -183,15 +182,15 @@ public class UriComponentsBuilderTests {
public
void
fromUriStringIPv6Host
()
throws
URISyntaxException
{
UriComponents
result
=
UriComponentsBuilder
.
fromUriString
(
"http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource"
).
build
().
encode
();
assertEquals
(
"[1abc:2abc:3abc::5ABC:6abc]"
,
result
.
getHost
());
assertEquals
(
"[1abc:2abc:3abc::5ABC:6abc]"
,
result
.
getHost
());
UriComponents
resultWithScopeId
=
UriComponentsBuilder
.
fromUriString
(
"http://[1abc:2abc:3abc::5ABC:6abc%eth0]:8080/resource"
).
build
().
encode
();
assertEquals
(
"[1abc:2abc:3abc::5ABC:6abc%25eth0]"
,
resultWithScopeId
.
getHost
());
assertEquals
(
"[1abc:2abc:3abc::5ABC:6abc%25eth0]"
,
resultWithScopeId
.
getHost
());
UriComponents
resultIPv4compatible
=
UriComponentsBuilder
.
fromUriString
(
"http://[::192.168.1.1]:8080/resource"
).
build
().
encode
();
assertEquals
(
"[::192.168.1.1]"
,
resultIPv4compatible
.
getHost
());
assertEquals
(
"[::192.168.1.1]"
,
resultIPv4compatible
.
getHost
());
}
@Test
...
...
spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java
浏览文件 @
92795f46
...
...
@@ -25,9 +25,7 @@ import java.net.URISyntaxException;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
...
...
@@ -45,20 +43,38 @@ public class UriComponentsTests {
@Test
public
void
toUriEncoded
()
throws
URISyntaxException
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/hotel list/Z\u00fcrich"
).
build
();
UriComponents
encoded
=
uriComponents
.
encode
();
assertEquals
(
new
URI
(
"http://example.com/hotel%20list/Z%C3%BCrich"
),
encoded
.
toUri
());
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/hotel list/Z\u00fcrich"
).
build
();
assertEquals
(
new
URI
(
"http://example.com/hotel%20list/Z%C3%BCrich"
),
uriComponents
.
encode
()
.
toUri
());
}
@Test
public
void
toUriNotEncoded
()
throws
URISyntaxException
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/hotel list/Z\u00fcrich"
).
build
();
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/hotel list/Z\u00fcrich"
).
build
();
assertEquals
(
new
URI
(
"http://example.com/hotel%20list/Z\u00fcrich"
),
uriComponents
.
toUri
());
}
@Test
public
void
toUriAlreadyEncoded
()
throws
URISyntaxException
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com/hotel%20list/Z%C3%BCrich"
).
build
(
true
);
UriComponents
encoded
=
uriComponents
.
encode
();
assertEquals
(
new
URI
(
"http://example.com/hotel%20list/Z%C3%BCrich"
),
encoded
.
toUri
());
}
@Test
public
void
toUriWithIpv6HostAlreadyEncoded
()
throws
URISyntaxException
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://[1abc:2abc:3abc::5ABC:6abc]:8080/hotel%20list/Z%C3%BCrich"
).
build
(
true
);
UriComponents
encoded
=
uriComponents
.
encode
();
assertEquals
(
new
URI
(
"http://[1abc:2abc:3abc::5ABC:6abc]:8080/hotel%20list/Z%C3%BCrich"
),
encoded
.
toUri
());
}
@Test
public
void
expand
()
{
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com"
).
path
(
"/{foo} {bar}"
).
build
();
UriComponents
uriComponents
=
UriComponentsBuilder
.
fromUriString
(
"http://example.com"
).
path
(
"/{foo} {bar}"
).
build
();
uriComponents
=
uriComponents
.
expand
(
"1 2"
,
"3 4"
);
assertEquals
(
"/1 2 3 4"
,
uriComponents
.
getPath
());
assertEquals
(
"http://example.com/1 2 3 4"
,
uriComponents
.
toUriString
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录