Merge "Merge branch 'stable-2.14'"

This commit is contained in:
David Pursehouse 2017-08-16 21:35:29 +00:00 committed by Gerrit Code Review
commit 569c27c379
1 changed files with 13 additions and 4 deletions

View File

@ -14,9 +14,13 @@
package com.google.gerrit.httpd;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.gerrit.common.Nullable;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
public class CanonicalWebUrl {
@ -35,10 +39,15 @@ public class CanonicalWebUrl {
static String computeFromRequest(HttpServletRequest req) {
StringBuffer url = req.getRequestURL();
url.setLength(url.length() - req.getServletPath().length());
if (url.charAt(url.length() - 1) != '/') {
url.append('/');
try {
url = new StringBuffer(URLDecoder.decode(url.toString(), UTF_8.name()));
url.setLength(url.length() - req.getServletPath().length());
if (url.charAt(url.length() - 1) != '/') {
url.append('/');
}
return url.toString();
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Unsupported encoding for request URL " + url, e);
}
return url.toString();
}
}