Allow greedy parameters (+) prior to a format paramter that consume everything but the last . #15213
+378
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
Grails by default doesn't use mime types to render json. It encourages using $format. If you want to handle multiple mime types with the same controller while supporting ids with decimals, this becomes impossible due to how regular expression url mappings are handled in Grails. This PR offers the capability of restricting format to not include periods by specifying the $id attribute to be greedy with the + symbol.
Problem
Currently when a url parameter is specified prior prior to a $format parameter, the parameter only consumes everything up until the first dot. This results in undesired behavior on sites that's use parameters for usernames that include 1 or more periods.
For instance
"/$controller/$action?/$id?(.$format)?"
/user/show/bob.smith.json results in controller = 'UserController' id = 'bob'. format = 'smith.json'
The solution
Introduce the + symbol after a url parameter to make it greedy.
Syntax:
Examples with this Fix
"/$controller/$action?/$id+?(.$format)?"
/user/show/est.test.json → id=test.test, format=json
/user/show/test.json → id=test, format=json
/user/show/foo.bar.baz.xml → id=foo.bar.baz, format=xml