Fix url redirection from searchview for weird urls
<title>Redirect</title>
<%
String url = request.getParameter("url");
-String baseUrl = url.substring(0, url.lastIndexOf("/") + 1);
+String baseUrl = url.substring(0, url.indexOf("/") + 1);
String browser = request.getHeader("user-agent");
if(baseUrl.startsWith("file:")) {
+ //Encode filename
String filename = url.substring(url.lastIndexOf("/") + 1);
filename = URLEncoder.encode(filename, StandardCharsets.UTF_8.name()).replaceAll("\\+", "%20");
- url = baseUrl + filename;
+ //Encode baseUrl
+ baseUrl = url.substring(url.indexOf("/"), url.lastIndexOf("/") + 1);
+ baseUrl = URLEncoder.encode(baseUrl, StandardCharsets.UTF_8.name()).replaceAll("%2F", "/").replaceAll("\\+", "%20");
+ url = "file:" + baseUrl + filename;
}
if(!browser.toLowerCase().contains("chrome") || baseUrl.startsWith("http")) {
response.sendRedirect(url);
