Skip to content

Commit e92bbc8

Browse files
committed
Revert "Improve suffix pattern check"
This reverts commit 3474afb. Unfortunately this change is likely to cause issues for applications that use regular expressions in a URI variable. I think we will have to leave at: if there are any dots in the last segment of the request path, regardless of whether they're in a URI var or not, the suffix pattern match is off. Issue: SPR-11532
1 parent 3347b45 commit e92bbc8

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ private String getMatchingPattern(String pattern, String lookupPath) {
249249
}
250250
}
251251
else {
252-
if (!hasSuffix(pattern) && this.pathMatcher.match(pattern + ".*", lookupPath)) {
252+
boolean hasSuffix = pattern.indexOf('.') != -1;
253+
if (!hasSuffix && this.pathMatcher.match(pattern + ".*", lookupPath)) {
253254
return pattern + ".*";
254255
}
255256
}
@@ -265,28 +266,6 @@ private String getMatchingPattern(String pattern, String lookupPath) {
265266
return null;
266267
}
267268

268-
private boolean hasSuffix(String pattern) {
269-
boolean uriVarMode = false;
270-
for (int i = pattern.length(); i > 0; i--) {
271-
char c = pattern.charAt(i-1);
272-
if (c == '}') {
273-
uriVarMode = true;
274-
}
275-
else if (c == '{') {
276-
uriVarMode = false;
277-
}
278-
else if (c == '/') {
279-
return false;
280-
}
281-
else {
282-
if (!uriVarMode && c == '.') {
283-
return true;
284-
}
285-
}
286-
}
287-
return false;
288-
}
289-
290269
/**
291270
* Compare the two conditions based on the URL patterns they contain.
292271
* Patterns are compared one at a time, from top to bottom via

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -115,26 +115,6 @@ public void matchSuffixPattern() {
115115
assertEquals("/{foo}", match.getPatterns().iterator().next());
116116
}
117117

118-
// SPR-11532
119-
120-
@Test
121-
public void matchSuffixPatternWithUriVariables() {
122-
testSuffixPattern("/employees/{areaOfResponsibility.owner.id}", "/employees/976685.json", false);
123-
testSuffixPattern("/establishments/{establishmentId}", "/establishments/123456789.json", false);
124-
testSuffixPattern("/a.b/c", "/a.b/c.json", false);
125-
testSuffixPattern("/a/b.json", "/a/b.json", true);
126-
testSuffixPattern("/a/{b}.{c}", "/a/b.c", true);
127-
}
128-
129-
public void testSuffixPattern(String pattern, String url, boolean patternHasSuffix) {
130-
MockHttpServletRequest request = new MockHttpServletRequest("GET", url);
131-
PatternsRequestCondition condition = new PatternsRequestCondition(pattern);
132-
PatternsRequestCondition match = condition.getMatchingCondition(request);
133-
134-
assertNotNull(match);
135-
assertEquals((patternHasSuffix ? pattern : pattern + ".*"), match.getPatterns().iterator().next());
136-
}
137-
138118
// SPR-8410
139119

140120
@Test

0 commit comments

Comments
 (0)