Skip to content

Commit e644392

Browse files
author
graeme
committed
fix for GRAILS-1540
git-svn-id: https://svn.codehaus.org/grails/trunk@5340 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 6832a24 commit e644392

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

src/web/org/codehaus/groovy/grails/web/mapping/DefaultUrlMappingsHolder.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,21 @@ public UrlCreator getReverseMapping(final String controller, final String action
111111
if(params == null) params = Collections.EMPTY_MAP;
112112

113113
UrlMapping mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(controller, action, params.keySet()));
114+
if(mapping == null) {
115+
mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(controller, action, Collections.EMPTY_SET));
116+
}
114117
if(mapping == null) {
115118
mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(controller, null, DEFAULT_ACTION_PARAMS));
116-
if(mapping == null) {
117-
mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(null, null, DEFAULT_CONTROLLER_PARAMS));
118-
if(mapping == null) {
119-
return new DefaultUrlCreator(controller, action);
120-
}
121-
else {
122-
return mapping;
123-
}
124-
}
125119
}
126-
return mapping;
120+
if(mapping == null) {
121+
mapping = (UrlMapping)mappingsLookup.get(new UrlMappingKey(null, null, DEFAULT_CONTROLLER_PARAMS));
122+
}
123+
if(mapping == null) {
124+
return new DefaultUrlCreator(controller, action);
125+
}
126+
else {
127+
return mapping;
128+
}
127129
}
128130

129131
/**
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Some more tests for the behaviour of reverse linking from mappings
3+
4+
* @author Graeme Rocher
5+
* @since 0.6
6+
*
7+
* Created: Aug 29, 2007
8+
* Time: 8:44:26 AM
9+
*
10+
*/
11+
package org.codehaus.groovy.grails.web.taglib
12+
13+
import org.codehaus.groovy.grails.commons.*
14+
15+
class OverlappingReverseMappedLinkTests extends AbstractGrailsTagTests {
16+
17+
18+
void onInit() {
19+
def mappingClass = gcl.parseClass('''
20+
class UrlMappings {
21+
static mappings = {
22+
"/authors" {
23+
controller = "author"
24+
action = "list"
25+
}
26+
27+
"/content/$controller/$action?/$id?"{
28+
constraints {
29+
// apply constraints here
30+
}
31+
}
32+
}
33+
}
34+
''')
35+
36+
grailsApplication.addArtefact(UrlMappingsArtefactHandler.TYPE, mappingClass)
37+
38+
}
39+
40+
41+
void testSimpleLink() {
42+
def expected = '<a href="/authors">link1</a>'
43+
assertOutputEquals(expected, '<g:link controller="author" action="list">link1</g:link>')
44+
}
45+
46+
void testLinkWithPaginationParams() {
47+
def expected = '<a href="/authors?max=10&offset=20">link1</a>'
48+
assertOutputEquals(expected, '<g:link controller="author" action="list" params="[max:10,offset:20]">link1</g:link>')
49+
}
50+
}

0 commit comments

Comments
 (0)