Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Oct 9, 2013
2 parents 2622b28 + c92d322 commit 6e939dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 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 @@ -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
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 6e939dd

Please sign in to comment.