Skip to content

Commit a5141b1

Browse files
committed
Fix '**' parsing within a PathPattern segment
Prior to this commit, a regexp path segment ending with a double wilcard (like "/path**") would be incorrectly parsed as a double wildcard segment ("/**"). This commit fixes the incorrect parsing. See gh-35679
1 parent d3c1e67 commit a5141b1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,22 @@ else if (ch == '}' && !previousBackslash) {
236236
}
237237

238238
private boolean isDoubleWildcard(char separator) {
239+
// next char is present
239240
if ((this.pos + 1) >= this.pathPatternLength) {
240241
return false;
241242
}
243+
// current char and next char are '*'
242244
if (this.pathPatternData[this.pos] != '*' || this.pathPatternData[this.pos + 1] != '*') {
243245
return false;
244246
}
245-
if ((this.pos + 2) < this.pathPatternLength) {
246-
return this.pathPatternData[this.pos + 2] == separator;
247+
// previous char is a separator, if any
248+
if ((this.pos - 1 >= 0) && (this.pathPatternData[this.pos - 1] != separator)) {
249+
return false;
250+
}
251+
// next char is a separator, if any
252+
if (((this.pos + 2) < this.pathPatternLength) &&
253+
this.pathPatternData[this.pos + 2] != separator) {
254+
return false;
247255
}
248256
return true;
249257
}

spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ void wildcardSegmentEndOfPathPatterns() {
8585

8686
@Test
8787
void regexpSegmentIsNotWildcardSegment() {
88-
// this is not double wildcard, it's / then **acb (an odd, unnecessary use of double *)
8988
pathPattern = checkStructure("/**acb");
9089
assertPathElements(pathPattern, SeparatorPathElement.class, RegexPathElement.class);
90+
91+
pathPattern = checkStructure("/a**bc");
92+
assertPathElements(pathPattern, SeparatorPathElement.class, RegexPathElement.class);
93+
94+
pathPattern = checkStructure("/abc**");
95+
assertPathElements(pathPattern, SeparatorPathElement.class, RegexPathElement.class);
9196
}
9297

9398
@Test

0 commit comments

Comments
 (0)