Skip to content

Commit d1df312

Browse files
committed
fix pathpattern-combine
1 parent 941b791 commit d1df312

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ else if (!StringUtils.hasLength(pattern2string.patternString)) {
397397
this.patternString.substring(0, this.patternString.length() - 2),
398398
pattern2string.patternString));
399399
}
400+
401+
if (this.patternString.endsWith("/*")) {
402+
String base = this.patternString.substring(0, this.patternString.length() - 2);
403+
if (pattern2string.patternString.contains("/")) {
404+
throw new IllegalArgumentException("Cannot combine single-segment wildcard '/*' with multi-segment path '" +
405+
pattern2string.patternString + "'");
406+
}
407+
return this.parser.parse(concat(base, "/" + pattern2string.patternString));
408+
}
400409

401410
// /hotels + /booking => /hotels/booking
402411
// /hotels + booking => /hotels/booking

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
3434
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
35+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3536

3637
/**
3738
* Exercise matching of {@link PathPattern} objects.

0 commit comments

Comments
 (0)