浏览代码

fix #2758 support urls containing #

Shinsuke Sugaya 2 年之前
父节点
当前提交
dea1cb29cd
共有 1 个文件被更改,包括 16 次插入11 次删除
  1. 16 11
      src/main/java/org/codelibs/fess/app/web/go/GoAction.java

+ 16 - 11
src/main/java/org/codelibs/fess/app/web/go/GoAction.java

@@ -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));
         }