Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
1e046435
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,发现更多精彩内容 >>
提交
1e046435
编写于
5月 09, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AntPathMatcher actually throws IllegalArgumentException if patterns cannot be combined
Issue: SPR-12998
上级
acfc95e2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
24 deletion
+26
-24
spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
...rc/main/java/org/springframework/util/AntPathMatcher.java
+24
-17
spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java
...st/java/org/springframework/util/AntPathMatcherTests.java
+2
-7
未找到文件。
spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
浏览文件 @
1e046435
...
...
@@ -419,12 +419,10 @@ public class AntPathMatcher implements PathMatcher {
/**
* Combine two patterns into a new pattern.
*
* <p>This implementation simply concatenates the two patterns, unless
* the first pattern contains a file extension match (e.g., {@code *.html}).
* In that case, the second pattern will be merged into the first. Otherwise,
* an {@code IllegalArgumentException} will be thrown.
*
* <h3>Examples</h3>
* <table border="1">
* <tr><th>Pattern 1</th><th>Pattern 2</th><th>Result</th></tr>
...
...
@@ -442,7 +440,6 @@ public class AntPathMatcher implements PathMatcher {
* <tr><td>/*.html</td><td>/hotels</td><td>/hotels.html</td></tr>
* <tr><td>/*.html</td><td>/*.txt</td><td>{@code IllegalArgumentException}</td></tr>
* </table>
*
* @param pattern1 the first pattern
* @param pattern2 the second pattern
* @return the combination of the two patterns
...
...
@@ -460,7 +457,7 @@ public class AntPathMatcher implements PathMatcher {
return
pattern1
;
}
boolean
pattern1ContainsUriVar
=
pattern1
.
indexOf
(
'{'
)
!=
-
1
;
boolean
pattern1ContainsUriVar
=
(
pattern1
.
indexOf
(
'{'
)
!=
-
1
)
;
if
(!
pattern1
.
equals
(
pattern2
)
&&
!
pattern1ContainsUriVar
&&
match
(
pattern1
,
pattern2
))
{
// /* + /hotel -> /hotel ; "/*.*" + "/*.html" -> /*.html
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
...
...
@@ -484,12 +481,18 @@ public class AntPathMatcher implements PathMatcher {
// simply concatenate the two patterns
return
concat
(
pattern1
,
pattern2
);
}
String
extension1
=
pattern1
.
substring
(
starDotPos1
+
1
);
String
ext1
=
pattern1
.
substring
(
starDotPos1
+
1
);
int
dotPos2
=
pattern2
.
indexOf
(
'.'
);
String
fileName2
=
(
dotPos2
==
-
1
?
pattern2
:
pattern2
.
substring
(
0
,
dotPos2
));
String
extension2
=
(
dotPos2
==
-
1
?
""
:
pattern2
.
substring
(
dotPos2
));
String
extension
=
extension1
.
startsWith
(
"*"
)
?
extension2
:
extension1
;
return
fileName2
+
extension
;
String
file2
=
(
dotPos2
==
-
1
?
pattern2
:
pattern2
.
substring
(
0
,
dotPos2
));
String
ext2
=
(
dotPos2
==
-
1
?
""
:
pattern2
.
substring
(
dotPos2
));
boolean
ext1All
=
(
ext1
.
equals
(
".*"
)
||
ext1
.
equals
(
""
));
boolean
ext2All
=
(
ext2
.
equals
(
".*"
)
||
ext2
.
equals
(
""
));
if
(!
ext1All
&&
!
ext2All
)
{
throw
new
IllegalArgumentException
(
"Cannot combine patterns: "
+
pattern1
+
" vs "
+
pattern2
);
}
String
ext
=
(
ext1All
?
ext2
:
ext1
);
return
file2
+
ext
;
}
private
String
concat
(
String
path1
,
String
path2
)
{
...
...
@@ -508,14 +511,18 @@ public class AntPathMatcher implements PathMatcher {
}
/**
* Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of explicitness.
* <p>The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
* java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
* generic patterns. So given a list with the following patterns: <ol> <li>{@code /hotels/new}</li>
* <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li> </ol> the returned comparator will sort this
* list so that the order will be as indicated.
* <p>The full path given as parameter is used to test for exact matches. So when the given path is {@code /hotels/2},
* the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
* Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of
* explicitness.
* <p>This{@code Comparator} will {@linkplain java.util.Collections#sort(List, Comparator) sort}
* a list so that more specific patterns (without uri templates or wild cards) come before
* generic patterns. So given a list with the following patterns:
* <ol>
* <li>{@code /hotels/new}</li>
* <li>{@code /hotels/{hotel}}</li> <li>{@code /hotels/*}</li>
* </ol>
* the returned comparator will sort this list so that the order will be as indicated.
* <p>The full path given as parameter is used to test for exact matches. So when the given path
* is {@code /hotels/2}, the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
* @param path the full path to use for comparison
* @return a comparator capable of sorting patterns in order of explicitness
*/
...
...
spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java
浏览文件 @
1e046435
...
...
@@ -44,15 +44,11 @@ import static org.junit.Assert.*;
*/
public
class
AntPathMatcherTests
{
private
AntPathMatcher
pathMatcher
;
private
final
AntPathMatcher
pathMatcher
=
new
AntPathMatcher
()
;
@Rule
public
ExpectedException
exception
=
ExpectedException
.
none
();
public
final
ExpectedException
exception
=
ExpectedException
.
none
();
@Before
public
void
createMatcher
()
{
pathMatcher
=
new
AntPathMatcher
();
}
@Test
public
void
match
()
{
...
...
@@ -432,7 +428,6 @@ public class AntPathMatcherTests {
assertEquals
(
"/hotel/booking"
,
pathMatcher
.
combine
(
"/hotel/"
,
"/booking"
));
// SPR-12975
}
@Ignore
(
"Disabled until SPR-12998 is resolved"
)
@Test
public
void
combineWithTwoFileExtensionPatterns
()
{
exception
.
expect
(
IllegalArgumentException
.
class
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录