[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Fix searches with multiple search terms.
commit ee394f9fed58e2b3e8afd85eab0019cd9e61cc24
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Mar 16 09:29:17 2015 +0100
Fix searches with multiple search terms.
Searches with multiple search terms were either broken in c13da0e or
when switching from Tomcat to Jetty.
Fixes #15267.
---
.../java/org/torproject/onionoo/server/ResourceServlet.java | 10 +++-------
.../org/torproject/onionoo/server/ResourceServletTest.java | 6 ++++++
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 6182704..8589e13 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -360,7 +360,7 @@ public class ResourceServlet extends HttpServlet {
private static Pattern searchQueryStringPattern =
Pattern.compile("(?:.*[\\?&])*?" // lazily skip other parameters
- + "search=([0-9a-zA-Z+/\\.: \\$\\[\\]]+)" // capture parameter
+ + "search=([0-9a-zA-Z+/\\.: \\$\\[\\]%]+)" // capture parameter
+ "(?:&.*)*"); // skip remaining parameters
private static Pattern searchParameterPattern =
Pattern.compile("^\\$?[0-9a-fA-F]{1,40}$|" /* Hex fingerprint. */
@@ -376,12 +376,8 @@ public class ResourceServlet extends HttpServlet {
return null;
}
String parameter = searchQueryStringMatcher.group(1);
- String[] searchParameters;
- if (parameter.contains(" ")) {
- searchParameters = parameter.split(" ");
- } else {
- searchParameters = new String[] { parameter };
- }
+ String[] searchParameters =
+ parameter.replaceAll("%20", " ").split(" ");
for (String searchParameter : searchParameters) {
if (!searchParameterPattern.matcher(searchParameter).matches()) {
/* Illegal search term. */
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index 83ffa5f..c6ef9c8 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -795,6 +795,12 @@ public class ResourceServletTest {
}
@Test()
+ public void testSearchTorkaZEscapedSpaceTypeRelay() {
+ this.assertSummaryDocument("/summary?search=TorkaZ%20type:relay", 1,
+ new String[] { "TorkaZ" }, 0, null);
+ }
+
+ @Test()
public void testSearchTypeRelayTypeDirectory() {
this.assertSummaryDocument(
"/summary?search=type:relay type:directory", 3, null, 0, null);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits