From b726b2b532207e5dc14e10dc792cfd1ca2ff9237 Mon Sep 17 00:00:00 2001 From: luccioman Date: Mon, 20 Aug 2018 08:10:39 +0200 Subject: [PATCH] Removed unnecessary '+' character URL decoding from search query Manually replacing '+' character or "%20" by a space character in the search query parameter was necessary in YaCy a long time ago to properly decode application/x-www-form-urlencoded format (commit 9842fab6e47f1dd93f5dc7ac6c2736a4ebaf93fa in 2010). Since the introduction of Jetty as the embedded HTTP server (commit 4b77733e59dd8af742ff826c90c8d40b542b7563 in 2013), this is no more necessary as Jetty internals already do this for us in org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(). So we can remove now this duplicated decoding as it prevents a proper use of the '+' character in search requests, as reported in issue #216. --- htroot/suggest.java | 2 +- htroot/yacysearch.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htroot/suggest.java b/htroot/suggest.java index 4d70c37f0..609a93ff0 100644 --- a/htroot/suggest.java +++ b/htroot/suggest.java @@ -62,7 +62,7 @@ public class suggest { // get query final String originalquerystring = (post == null) ? "" : post.get("query", post.get("q", "")); - final String querystring = originalquerystring.replace('+', ' ').replaceAll("%20", " "); + final String querystring = originalquerystring.trim(); final int timeout = (post == null) ? 300 : post.getInt("timeout", 300); final int count = (post == null) ? 10 : Math.min(30, post.getInt("count", 20)); diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 0144dc17b..909c96652 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -134,7 +134,7 @@ public class yacysearch { final boolean focus = (post == null) ? true : post.get("focus", "1").equals("1"); // get query final String originalquerystring = (post == null) ? "" : post.get("query", post.get("search", "")).trim(); - String querystring = originalquerystring.replace('+', ' ').trim(); + String querystring = originalquerystring; CacheStrategy snippetFetchStrategy = (post == null) ? null : CacheStrategy.parse(post.get("verify", sb.getConfig("search.verify", ""))); final servletProperties prop = new servletProperties();