Skip to content

Commit cc05608

Browse files
committed
PathPattern does not use custom separator
Prior to this commit, `PathPattern::extractPathWithinMapping` would always use the default path pattern separator `/` when extracting the path within the pattern of a matched route. This commit ensures that `PathPattern` uses the configured separator when extracting the path within the matched mapping. Fixes gh-23168
1 parent 5787fc1 commit cc05608

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public PathContainer extractPathWithinPattern(PathContainer path) {
339339
}
340340
}
341341
}
342-
resultPath = PathContainer.parsePath(buf.toString());
342+
resultPath = PathContainer.parsePath(buf.toString(), String.valueOf(this.separator));
343343
}
344344
else if (startIndex >= endIndex) {
345345
resultPath = PathContainer.parsePath("");

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,17 @@ public void extractPathWithinPattern() throws Exception {
707707
checkExtractPathWithinPattern("/", "//", "");
708708
}
709709

710+
@Test
711+
public void extractPathWithinPatternCustomSeparator() {
712+
PathPatternParser ppp = new PathPatternParser();
713+
ppp.setSeparator('.');
714+
PathPattern pp = ppp.parse("test.**");
715+
PathContainer pathContainer = PathContainer.parsePath("test.projects..spring-framework", ".");
716+
PathContainer result = pp.extractPathWithinPattern(pathContainer);
717+
assertThat(result.value()).isEqualTo("projects.spring-framework");
718+
assertThat(result.elements()).hasSize(3);
719+
}
720+
710721
@Test
711722
public void extractUriTemplateVariables_spr15264() {
712723
PathPattern pp;

0 commit comments

Comments
 (0)