Skip to content

Commit 0d2a0d7

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. Fixes gh-35339
1 parent a999dd1 commit 0d2a0d7

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
@@ -234,14 +234,22 @@ else if (ch == '}' && !previousBackslash) {
234234
}
235235

236236
private boolean isDoubleWildcard(char separator) {
237+
// next char is present
237238
if ((this.pos + 1) >= this.pathPatternLength) {
238239
return false;
239240
}
241+
// current char and next char are '*'
240242
if (this.pathPatternData[this.pos] != '*' || this.pathPatternData[this.pos + 1] != '*') {
241243
return false;
242244
}
243-
if ((this.pos + 2) < this.pathPatternLength) {
244-
return this.pathPatternData[this.pos + 2] == separator;
245+
// previous char is a separator, if any
246+
if ((this.pos - 1 >= 0) && (this.pathPatternData[this.pos - 1] != separator)) {
247+
return false;
248+
}
249+
// next char is a separator, if any
250+
if (((this.pos + 2) < this.pathPatternLength) &&
251+
this.pathPatternData[this.pos + 2] != separator) {
252+
return false;
245253
}
246254
return true;
247255
}

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)