Skip to content
Browse files

Prevent url encoding for controller and action

Currently, the controller name and action name are url-encoded when creating an HTML link.
But I want to be able to configure my controller to have a featureUri with a slash in it - e.g. "admin/myController". This should be possible using the UrlMappings framework, but currently fails because the slash is encoded to "%2F" by the LinkGenerator. So the URI becomes "admin%2FmyController".
This patch prevents URL-encoding the controller name and action, when creating a URL.
  • Loading branch information...
1 parent 6db1d27 commit 04b45cab83f3fed0ed1e7afb0f979017c97d5a1f @mckenfra committed
View
17 ...rl-mappings/src/main/groovy/org/codehaus/groovy/grails/web/mapping/DefaultUrlCreator.java
@@ -87,13 +87,13 @@ private String createURLWithWebRequest(Map parameterValues, GrailsWebRequest web
}
else {
if (controllerName != null) {
- appendUrlToken(actualUriBuf, controllerName, encoding);
+ appendUrlToken(actualUriBuf, controllerName, encoding, false);
}
else {
- appendUrlToken(actualUriBuf, requestStateLookupStrategy.getControllerName(), encoding);
+ appendUrlToken(actualUriBuf, requestStateLookupStrategy.getControllerName(), encoding, false);
}
}
- appendUrlToken(actualUriBuf, actionName, encoding);
+ appendUrlToken(actualUriBuf, actionName, encoding, false);
}
if (id != null) {
appendUrlToken(actualUriBuf, id, encoding);
@@ -240,9 +240,18 @@ private String urlEncode(Object obj, String charset) {
}
/*
+ * Appends a URL token to the buffer. Always url encodes the token before append.
+ */
+ protected void appendUrlToken(FastStringWriter actualUriBuf, Object token, String charset) {
+ appendUrlToken(actualUriBuf, token, charset, true);
+ }
+
+ /*
* Appends a URL token to the buffer
+ *
+ * @param urlEncode If true, url encodes the token before append
*/
- private void appendUrlToken(FastStringWriter actualUriBuf, Object token, String charset) {
+ protected void appendUrlToken(FastStringWriter actualUriBuf, Object token, String charset, boolean urlEncode) {
actualUriBuf.append(SLASH).append(urlEncode(token, charset));
}
}

0 comments on commit 04b45ca

Please sign in to comment.
Something went wrong with that request. Please try again.