Skip to content

Commit e4f7dda

Browse files
Merge branch '2.3.x' into 2.4.x
Conflicts: grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/mapping/RegexUrlMappingTests.groovy
2 parents de6cc0e + 3852456 commit e4f7dda

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/mapping/RegexUrlMappingTests.groovy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,26 @@ mappings {
6969
controller = 'hyphenTests'
7070
action = 'view'
7171
}
72+
"/plugins/grails-$plugin/tags/RELEASE_$version/$fullName(.$type)" {
73+
controller = 'website'
74+
action = 'displayPlugin'
75+
}
7276
}
7377
'''
74-
78+
79+
void testExtensionPrecededByTokenWhichMayContainDots() {
80+
def holder = new DefaultUrlMappingsHolder(evaluator.evaluateMappings(new ByteArrayResource(mappingScript.bytes)))
81+
82+
def info = holder.match("/plugins/grails-csv/tags/RELEASE_0.3.1/csv-0.3.1.pom")
83+
assertNotNull info
84+
assertEquals 'website', info.controllerName
85+
assertEquals 'displayPlugin', info.actionName
86+
assertEquals '0.3.1', info.params.version
87+
assertEquals 'csv', info.params.plugin
88+
assertEquals 'csv-0.3.1', info.params.fullName
89+
assertEquals 'pom', info.params.type
90+
}
91+
7592
void testHyphenDelimiters() {
7693
def holder = new DefaultUrlMappingsHolder(evaluator.evaluateMappings(new ByteArrayResource(mappingScript.bytes)))
7794

grails-web-url-mappings/src/main/groovy/org/codehaus/groovy/grails/web/mapping/RegexUrlMapping.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,21 @@ protected Pattern convertToRegex(String url) {
228228
.replaceAll("([^\\*])\\*$", "$1[^/]+")
229229
.replaceAll("\\*\\*", ".*");
230230

231-
pattern += urlEnd
231+
if("/(*)(\\.(*))".equals(urlEnd)) {
232+
// shortcut this common special case which will
233+
// happen any time a URL mapping ends with a pattern like
234+
// /$someVariable(.$someExtension)
235+
pattern += "/([^/]+)\\.([^/.]+)?";
236+
} else {
237+
pattern += urlEnd
232238
.replace("(\\.(*))", "\\.?([^/]+)?")
233239
.replaceAll("([^\\*])\\*([^\\*])", "$1[^/]+$2")
234240
.replaceAll("([^\\*])\\*$", "$1[^/]+")
235241
.replaceAll("\\*\\*", ".*")
236242
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\\\\\.", "([^/.]+)\\\\.")
237243
.replaceAll("\\(\\[\\^\\/\\]\\+\\)\\?\\\\\\.", "([^/.]+)\\?\\\\.")
238244
;
239-
245+
}
240246
pattern += "/??$";
241247
regex = Pattern.compile(pattern);
242248
}

0 commit comments

Comments
 (0)