WARN against invalid patterns with PathPatternParser

As of gh-24952, `PathPatternParser` will strictly reject patterns with
`"**"` in the middle of them. `"**"` is only allowed at the end of the
pattern for matching multiple path segments until the end of the path.

Currently, if `"**"` is used in the middle of a pattern it will be
considered as a single `"*"` instead. Rejecting such cases should
clarify the situation.

This commit prepares for that upcoming change and:

* logs a warning message if such a case is used by an application
* expands the MVC and WebFlux documentation about URI matching in
general

Closes gh-24958
This commit is contained in:
Brian Clozel
2020-04-23 12:48:07 +02:00
parent 5eba1ae73c
commit dc4cda1b13
5 changed files with 94 additions and 14 deletions

View File

@@ -1402,12 +1402,44 @@ The following example uses type and method level mappings:
You can map requests by using glob patterns and wildcards:
* `?` matches one character
* `*` matches zero or more characters within a path segment
* `**` match zero or more path segments
[cols="2,3,5"]
|===
|Pattern |Description |Example
You can also declare URI variables and access their values with `@PathVariable`,
as the following example shows:
| `+?+`
| Matches one character
| `+"/pages/t?st.html"+`
matches `+"/pages/test.html"+`
and `+"/pages/t3st.html"+`
| `+*+`
| Matches zero or more characters within a path segment
| `+"/resources/*.png"+` matches `+"/resources/file.png"+`
`+"/projects/*/versions"+` matches `+"/projects/spring/versions"+` but does not match `+"/projects/spring/boot/versions"+`
| `+**+`
| Matches zero or more path segments until the end of the path
| `+"/resources/**"+` matches `+"/resources/file.png"+` and `+"/resources/images/file.png"+`
`+"/resources/**/file.png"+` is invalid as `+**+` is only allowed at the end of the path.
| `+{name}+`
| Matches a path segment and captures it as a variable named "name"
| `+"/projects/{project}/versions"+` matches `+"/projects/spring/versions"+` and captures `+project=spring+`
| `+{name:[a-z]+}+`
| Matches the regexp `+"[a-z]+"+` as a path variable named "name"
| `+"/projects/{project:[a-z]+}/versions"+` matches `+"/projects/spring/versions"+` but not `+"/projects/spring1/versions"+`
| `+{*path}+`
| Matches zero or more path segments until the end of the path and captures it as a variable named "path"
| `+"/resources/{*file}"+` matches `+"/resources/images/file.png"+` and captures `+file=resources/file.png+`
|===
Captured URI variables can be accessed with `@PathVariable`, as the following example shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java

View File

@@ -1535,14 +1535,40 @@ The following example has type and method level mappings:
==== URI patterns
[.small]#<<web-reactive.adoc#webflux-ann-requestmapping-uri-templates, WebFlux>>#
You can map requests by using the following global patterns and wildcards:
You can map requests by using glob patterns and wildcards:
* `?` matches one character
* `*` matches zero or more characters within a path segment
* `**` match zero or more path segments
[cols="2,3,5"]
|===
|Pattern |Description |Example
You can also declare URI variables and access their values with `@PathVariable`,
as the following example shows:
| `+?+`
| Matches one character
| `+"/pages/t?st.html"+`
matches `+"/pages/test.html"+`
and `+"/pages/t3st.html"+`
| `+*+`
| Matches zero or more characters within a path segment
| `+"/resources/*.png"+` matches `+"/resources/file.png"+`
`+"/projects/*/versions"+` matches `+"/projects/spring/versions"+` but does not match `+"/projects/spring/boot/versions"+`
| `+**+`
| Matches zero or more path segments until the end of the path
| `+"/resources/**"+` matches `+"/resources/file.png"+` and `+"/resources/images/file.png"+`
| `+{name}+`
| Matches a path segment and captures it as a variable named "name"
| `+"/projects/{project}/versions"+` matches `+"/projects/spring/versions"+` and captures `+project=spring+`
| `+{name:[a-z]+}+`
| Matches the regexp `+"[a-z]+"+` as a path variable named "name"
| `+"/projects/{project:[a-z]+}/versions"+` matches `+"/projects/spring/versions"+` but not `+"/projects/spring1/versions"+`
|===
Captured URI variables can be accessed with `@PathVariable`, as the following example shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java