Skip to content

Commit 610d1ff

Browse files
committed
Ensure parent constraints are added before nested contraints. Fixes #10246
1 parent fa8a398 commit 610d1ff

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ private String establishFullURI(String uri, List<ConstrainedProperty> constraine
777777

778778
if(!isInCollection) {
779779
uriBuilder.append(SLASH).append(CAPTURING_WILD_CARD);
780-
constrainedList.add(new ConstrainedProperty(UrlMapping.class, parentResource.controllerName + "Id", String.class));
781780
}
782781
}
783782
}
@@ -1199,6 +1198,12 @@ protected MetaMappingInfo pushNewMetaMappingInfo() {
11991198
if (parentMappingConstraints != null) {
12001199
mappingInfo.getConstraints().addAll(parentMappingConstraints);
12011200
}
1201+
ParentResource parentResource = parentResources.peek();
1202+
if(parentResource != null && !parentResource.isSingle) {
1203+
if(!isInCollection) {
1204+
mappingInfo.getConstraints().add(new ConstrainedProperty(UrlMapping.class, parentResource.controllerName + "Id", String.class));
1205+
}
1206+
}
12021207
}
12031208
if (previousConstraints.size() > 0) {
12041209
mappingInfo.getConstraints().addAll(previousConstraints);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.grails.web.mapping
2+
3+
import org.codehaus.groovy.grails.web.mapping.AbstractUrlMappingsSpec
4+
import spock.lang.Issue
5+
6+
/**
7+
* Created by graemerocher on 25/10/16.
8+
*/
9+
class NestedMappingWithinGroupSpec extends AbstractUrlMappingsSpec {
10+
11+
@Issue('https://github.com/grails/grails-core/issues/10246')
12+
void "test nested mapping within group"() {
13+
given:"A link generator with nested mappings withihn a group"
14+
def linkGenerator = getLinkGenerator {
15+
group("/api") {
16+
"/customer-stores"(resources: 'store') {
17+
"/catalogs"(controller: 'catalog', action: 'index', method: 'GET')
18+
"/catalogs/$catalogId/items"(controller: 'catalog', action: 'getItems', method: 'GET')
19+
}
20+
}
21+
}
22+
23+
expect:"The generated links to be correct"
24+
linkGenerator.link(controller:"catalog", action:"index", method:"GET", params:[storeId:'1']) == 'http://localhost/api/customer-stores/1/catalogs'
25+
linkGenerator.link(controller:"catalog", action:"getItems", method:"GET", params:[storeId:'1', catalogId:'2']) == 'http://localhost/api/customer-stores/1/catalogs/2/items'
26+
}
27+
}

0 commit comments

Comments
 (0)