Skip to content

Commit

Permalink
GRAILS-10500 - fix url mapping support for parameters that include a dot
Browse files Browse the repository at this point in the history
Only exclude dots from url elements if the element is immediately followed by a dot.

This is related to grails@20aa322#diff-fc4e5a151130dd0c3eaaf8838e48664fR198
  • Loading branch information
Jeff Scott Brown committed Oct 9, 2013
1 parent 8e2b99e commit c92d322
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -232,7 +232,7 @@ protected Pattern convertToRegex(String url) {
.replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+$2")
.replaceAll("([^\\*])\\*$", "$1[^/]+")
.replaceAll("\\*\\*", ".*")
// .replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+)\\\\.")
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+)\\\\.")
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\?\\\\\\.", "([^/.]+)\\?\\\\.")
;

Expand Down
Expand Up @@ -34,7 +34,7 @@ class UrlMappingRsWithOptionalExtensionSpec extends AbstractUrlMappingsSpec {

}

void "Test that dynamic URL mappings can be specified with an optional extension"() {
void "Test that dynamic URL mappings can be specified with an optional parameter and an optional extension"() {
given:"A URL mapping with an optional extension"
def urlMappingsHolder = getUrlMappingsHolder {
"/$controller/$action?(.$format)?"()
Expand All @@ -46,8 +46,19 @@ class UrlMappingRsWithOptionalExtensionSpec extends AbstractUrlMappingsSpec {
urlMappingsHolder.match('/book')
urlMappingsHolder.match('/book/list')
urlMappingsHolder.match('/book/list').parameters.format == null
}


void "Test that dynamic URL mappings can be specified with a required parameter and an optional extension"() {
given:"A URL mapping with an optional extension"
def urlMappingsHolder = getUrlMappingsHolder {
"/$controller/$action(.$format)?"()
}

expect:"URLs with and without the format specified match"
urlMappingsHolder.match('/book/list.xml')
urlMappingsHolder.match('/book/list.xml').parameters.format == 'xml'
urlMappingsHolder.match('/book/list')
urlMappingsHolder.match('/book/list').parameters.format == null
}

void "Test deep dynamic URL mappings can be specified with an optional extension"() {
Expand Down

0 comments on commit c92d322

Please sign in to comment.