Skip to content

Commit

Permalink
GRAILS-11526 - improve URL mapping extension handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Jun 23, 2014
1 parent bce7c37 commit 3852456
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,21 @@ protected Pattern convertToRegex(String url) {
.replaceAll("([^\\*])\\*$", "$1[^/]+")
.replaceAll("\\*\\*", ".*");

pattern += urlEnd
if("/(*)(\\.(*))".equals(urlEnd)) {
// shortcut this common special case which will
// happen any time a URL mapping ends with a pattern like
// /$someVariable(.$someExtension)
pattern += "/([^/]+)\\.([^/.]+)?";
} else {
pattern += urlEnd
.replace("(\\.(*))", "\\.?([^/]+)?")
.replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+$2")
.replaceAll("([^\\*])\\*$", "$1[^/]+")
.replaceAll("\\*\\*", ".*")
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+)\\\\.")
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\?\\\\\\.", "([^/.]+)\\?\\\\.")
;

}
pattern += "/??$";
regex = Pattern.compile(pattern);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,26 @@ mappings {
controller = 'hyphenTests'
action = 'view'
}
"/plugins/grails-$plugin/tags/RELEASE_$version/$fullName(.$type)" {
controller = 'website'
action = 'displayPlugin'
}
}
'''

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

def info = holder.match("/plugins/grails-csv/tags/RELEASE_0.3.1/csv-0.3.1.pom")
assertNotNull info
assertEquals 'website', info.controllerName
assertEquals 'displayPlugin', info.actionName
assertEquals '0.3.1', info.params.version
assertEquals 'csv', info.params.plugin
assertEquals 'csv-0.3.1', info.params.fullName
assertEquals 'pom', info.params.type
}

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

Expand Down

0 comments on commit 3852456

Please sign in to comment.