fix #2758 support urls containing #

This commit is contained in:
Shinsuke Sugaya 2023-07-16 05:59:09 +09:00
parent 06acb81618
commit dea1cb29cd

View file

@ -106,27 +106,32 @@ public class GoAction extends FessSearchAction {
}
}
final String targetUrl = pathMappingHelper.replaceUrl(url);
String hash;
if (StringUtil.isNotBlank(form.hash)) {
final String value = URLUtil.decode(form.hash, Constants.UTF_8);
final StringBuilder buf = new StringBuilder(value.length() + 100);
for (final char c : value.toCharArray()) {
if (CharUtil.isUrlChar(c) || c == ' ') {
buf.append(c);
} else {
try {
buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8));
} catch (final UnsupportedEncodingException e) {
// NOP
if (targetUrl.indexOf('#') == -1) {
final StringBuilder buf = new StringBuilder(value.length() + 100);
for (final char c : value.toCharArray()) {
if (CharUtil.isUrlChar(c) || c == ' ') {
buf.append(c);
} else {
try {
buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8));
} catch (final UnsupportedEncodingException e) {
// NOP
}
}
}
hash = buf.toString();
} else {
hash = StringUtil.EMPTY;
}
hash = buf.toString();
} else {
hash = StringUtil.EMPTY;
}
final String targetUrl = pathMappingHelper.replaceUrl(url);
if (!isFileSystemPath(targetUrl)) {
return HtmlResponse.fromRedirectPathAsIs(DocumentUtil.encodeUrl(targetUrl + hash));
}