Skip to content

Commit 41c719b

Browse files
GRAILS-11748 - fix params.action for resource mappings
All of the mappings for a particular resource were sharing a Map so the action of the last one created was being shared. Since delete was the last one created at https://github.com/grails/grails-core/blob/8c5d540797cd374c176e82aee7ca78e6dffaaf20/grails-web-url-mappings/src/main/groovy/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingEvaluator.java#L638, all of the mappings for that resource shared a params.action of "delete".
1 parent 03a0710 commit 41c719b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ private void configureUrlMapping(UrlMapping urlMapping) {
836836
parameterValues.put("action", urlMapping.getActionName());
837837
}
838838

839-
urlMapping.setParameterValues(parameterValues);
839+
urlMapping.setParameterValues(new LinkedHashMap(parameterValues));
840840
urlMappings.add(urlMapping);
841841
}
842842

grails-web-url-mappings/src/test/groovy/org/codehaus/groovy/grails/web/mapping/RestfulResourceMappingSpec.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ import spock.lang.Specification
1414
*/
1515
class RestfulResourceMappingSpec extends Specification{
1616

17+
@Issue('GRAILS-11748')
18+
void 'Test params.action'() {
19+
given:
20+
def urlMappingsHolder = getUrlMappingsHolder {
21+
"/books"(resources: "book")
22+
"/owner"(resource: "person")
23+
}
24+
25+
when:
26+
def urlMappings = urlMappingsHolder.urlMappings
27+
28+
then:
29+
urlMappingsHolder.matchAll('/books', 'GET')[0].parameters.action == 'index'
30+
urlMappingsHolder.matchAll('/books/create', 'GET')[0].parameters.action == 'create'
31+
urlMappingsHolder.matchAll('/books', 'POST')[0].parameters.action == 'save'
32+
urlMappingsHolder.matchAll('/books/42', 'GET')[0].parameters.action == 'show'
33+
urlMappingsHolder.matchAll('/books/42/edit', 'GET')[0].parameters.action == 'edit'
34+
urlMappingsHolder.matchAll('/books/42', 'PUT')[0].parameters.action == 'update'
35+
urlMappingsHolder.matchAll('/books/42', 'DELETE')[0].parameters.action == 'delete'
36+
37+
urlMappingsHolder.matchAll('/owner/create', 'GET')[0].parameters.action == 'create'
38+
urlMappingsHolder.matchAll('/owner', 'POST')[0].parameters.action == 'save'
39+
urlMappingsHolder.matchAll('/owner', 'GET')[0].parameters.action == 'show'
40+
urlMappingsHolder.matchAll('/owner/edit', 'GET')[0].parameters.action == 'edit'
41+
urlMappingsHolder.matchAll('/owner', 'PUT')[0].parameters.action == 'update'
42+
urlMappingsHolder.matchAll('/owner', 'DELETE')[0].parameters.action == 'delete'
43+
}
44+
1745
@Issue('GRAILS-11680')
1846
@Ignore
1947
void 'Test mapping ordering problem'() {

0 commit comments

Comments
 (0)