Skip to content

Commit 57d047b

Browse files
committed
Don't append the URI if it is a slash. Fixes #10210
1 parent 610d1ff commit 57d047b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,9 @@ private String establishFullURI(String uri, List<ConstrainedProperty> constraine
781781
}
782782
}
783783

784-
uriBuilder.append(uri);
784+
if(!SLASH.equals(uri)) {
785+
uriBuilder.append(uri);
786+
}
785787
return uriBuilder.toString();
786788
}
787789

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.grails.web.mapping
2+
3+
import grails.web.mapping.LinkGenerator
4+
import org.codehaus.groovy.grails.web.mapping.AbstractUrlMappingsSpec
5+
import spock.lang.Issue
6+
7+
/**
8+
* Created by graemerocher on 25/10/16.
9+
*/
10+
class ResourcesWithSingleSlashSpec extends AbstractUrlMappingsSpec {
11+
12+
@Issue('https://github.com/grails/grails-core/issues/10210')
13+
void "test that resources expressed with a single slash product the correct URI"() {
14+
given:"url mappings within groups with resources expressed with a single slash"
15+
LinkGenerator linkGenerator = getLinkGenerator {
16+
group "/api", {
17+
group "/v1", {
18+
group "/books", {
19+
"/" resources:"book"
20+
}
21+
}
22+
}
23+
}
24+
25+
expect:
26+
linkGenerator.link(resource:"book", id:1L, method:"GET") == 'http://localhost/api/v1/books/1'
27+
}
28+
}

0 commit comments

Comments
 (0)