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 20aa322#diff-fc4e5a151130dd0c3eaaf8838e48664fR198
  • Loading branch information
Jeff Scott Brown committed Oct 8, 2013
1 parent a5062cd commit 8e2b99e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Expand Up @@ -220,7 +220,6 @@ protected Pattern convertToRegex(String url) {
String urlRoot = lastSlash > -1 ? pattern.substring(0, lastSlash) : pattern;
String urlEnd = lastSlash > -1 ? pattern.substring(lastSlash, pattern.length()) : "";


// Now replace "*" with "[^/]" and "**" with ".*".
pattern = "^" + urlRoot
.replace("(\\.(*))", "\\.?([^/]+)?")
Expand All @@ -230,9 +229,12 @@ protected Pattern convertToRegex(String url) {

pattern += urlEnd
.replace("(\\.(*))", "\\.?([^/]+)?")
.replaceAll("([^\\*])\\*([^\\*])", "$1[^/\\.]+$2")
.replaceAll("([^\\*])\\*$", "$1[^/\\.]+")
.replaceAll("\\*\\*", ".*");
.replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+$2")
.replaceAll("([^\\*])\\*$", "$1[^/]+")
.replaceAll("\\*\\*", ".*")
// .replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+)\\\\.")
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\?\\\\\\.", "([^/.]+)\\?\\\\.")
;

pattern += "/??$";
regex = Pattern.compile(pattern);
Expand Down
Expand Up @@ -61,6 +61,10 @@ mappings {
controller = "survey"
action = "viewByName"
}
"/reports/$foo" {
controller = 'reporting'
action = 'view'
}
}
'''
void testMaptoURI() {
Expand Down Expand Up @@ -352,6 +356,22 @@ mappings {
assertEquals 'survey', info.controllerName
assertEquals 'viewByName', info.actionName
}

void testParameterContainingADot() {
def holder = new DefaultUrlMappingsHolder(evaluator.evaluateMappings(new ByteArrayResource(mappingScript.bytes)))

def info = holder.match("/reports/my")
assertNotNull info
assertEquals 'reporting', info.controllerName
assertEquals 'view', info.actionName
assertEquals 'my', info.params.foo

info = holder.match("/reports/my.id")
assertNotNull info
assertEquals 'reporting', info.controllerName
assertEquals 'view', info.actionName
assertEquals 'my.id', info.params.foo
}

void testInit() {
def parser = new DefaultUrlMappingParser()
Expand Down

0 comments on commit 8e2b99e

Please sign in to comment.