Skip to content

Commit 74e2c05

Browse files
committed
Merge pull request #488 from candrews/patch-8
GRAILS-11333: Handle already absolute URLs
2 parents c189fa5 + 49b22c5 commit 74e2c05

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/mapping/DefaultLinkGenerator.groovy

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware{
6565
def writer = new StringBuilder()
6666
// prefer URI attribute
6767
if (attrs.get(ATTRIBUTE_URI) != null) {
68-
final base = handleAbsolute(attrs)
69-
if (base != null) {
70-
writer << base
71-
}
72-
else {
73-
final cp = attrs.get(ATTRIBUTE_CONTEXT_PATH)
74-
if (cp == null) cp = getContextPath()
75-
if (cp != null)
76-
writer << cp
77-
}
7868
final uriPath = attrs.get(ATTRIBUTE_URI).toString()
69+
if(!isAbsoluteUri(uriPath)){
70+
final base = handleAbsolute(attrs)
71+
if (base != null) {
72+
writer << base
73+
}
74+
else {
75+
final cp = attrs.get(ATTRIBUTE_CONTEXT_PATH)
76+
if (cp == null) cp = getContextPath()
77+
if (cp != null)
78+
writer << cp
79+
}
80+
}
7981
writer << uriPath
8082
}
8183
else {
@@ -244,6 +246,15 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware{
244246
}
245247
}
246248

249+
private boolean isUriAbsolute(String uri){
250+
try{
251+
return new URI(uri).absolute
252+
}catch(Exception e){
253+
// assume unparseable URIs are absolute
254+
return true
255+
}
256+
}
257+
247258
/**
248259
* Get the declared URL of the server from config, or guess at localhost for non-production.
249260
*/

0 commit comments

Comments
 (0)