Skip to content

Commit

Permalink
Fix absolute reverse routing when using {_} as host part placeholder …
Browse files Browse the repository at this point in the history
…in routes
  • Loading branch information
guillaumebort committed Apr 11, 2011
1 parent b961ad0 commit 2b55149
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions framework/src/play/mvc/Router.java
Expand Up @@ -319,7 +319,7 @@ public static ActionDefinition reverse(String action) {

public static String getFullUrl(String action, Map<String, Object> args) {
ActionDefinition actionDefinition = reverse(action, args);
if(actionDefinition.method.equals("WS")) {
if (actionDefinition.method.equals("WS")) {
return Http.Request.current().getBase().replaceFirst("https?", "ws") + actionDefinition;
}
return Http.Request.current().getBase() + actionDefinition;
Expand Down Expand Up @@ -386,7 +386,7 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
for (String key : Scope.RouteArgs.current().data.keySet()) {
if (!args.containsKey(key)) {
args.put(key, Scope.RouteArgs.current().data.get(key));
}
}
}
}
for (Route route : routes) {
Expand Down Expand Up @@ -578,13 +578,27 @@ public String toString() {
}

public void absolute() {
String hostPart = host;
String domain = Http.Request.current().domain;
int port = Http.Request.current().port;
if (port != 80 && port != 443) {
hostPart += ":" + port;
}
// ~
if (!url.startsWith("http")) {
if (StringUtils.isEmpty(host)) {
url = Http.Request.current().getBase() + url;
} else if (host.contains("{_}")) {
java.util.regex.Matcher matcher = java.util.regex.Pattern.compile("([-_a-z0-9A-Z]+([.][-_a-z0-9A-Z]+)?)$").matcher(domain);
if (matcher.find()) {
url = (Http.Request.current().secure ? "https://" : "http://") + hostPart.replace("{_}", matcher.group(1)) + url;
} else {
url = (Http.Request.current().secure ? "https://" : "http://") + hostPart + url;
}
} else {
url = (Http.Request.current().secure ? "https://" : "http://") + host + url;
url = (Http.Request.current().secure ? "https://" : "http://") + hostPart + url;
}
if(method.equals("WS")) {
if (method.equals("WS")) {
url = url.replaceFirst("https?", "ws");
}
}
Expand Down

0 comments on commit 2b55149

Please sign in to comment.