Affects: 5.3.12
In my Spingboot app, I use @GetMapping and @RequestMapping to map the url path to the controller method which I expect Spring to do exact match
@Controller
@RequestMapping("/api")
class BlogController {
@GetMapping("/method1")
fun method1(model: Model):String {
return "template1"
}
@GetMapping("/method2")
fun method2(model: Model):String {
return "template2"
}
}
However, when I try visit this application with the url like http://localhost:8080/api;somethingelse/method1
which I expect it to return not found (404), Springboot return me the method1
result which I'm not expected.
I tried debug and found that the issue is with PathPattern
that matches /api;somethingelse/method1
with /api/method1
. Here are sample small code that I use to test this problem.
fun main(args: Array<String>) {
val patternMatcher = PathPatternParser().parse("/api/method1")
// I expect this to not match
println(patternMatcher.matches(PathContainer.parsePath("/api;something-else/method1")))
// This matches correctly
println(patternMatcher.matches(PathContainer.parsePath("/api/method1")))
// This is not matched
println(patternMatcher.matches(PathContainer.parsePath("/api1/method1")))
}
Comment From: bclozel
This is the expected behavior.
Those are path parameters (so, not strictly part of the path segment), see rfc3986 section-3.3. We're also describing this feature as "matrix variables" in the reference documentation - note that this link points to the WebFlux variant, because PathPattern
is the default implementation in WebFlux and should soon be the default for MVC as well.
Thanks!