[tor-commits] [onionoo/master] Support email addresses in qualified search terms.

karsten at torproject.org karsten at torproject.org
Fri Jan 6 19:52:42 UTC 2017


commit 66a1986644d919b426c4de562043cda559bca5ac
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Fri Jan 6 19:53:54 2017 +0100

    Support email addresses in qualified search terms.
    
    More generally, accept the same characters in qualified search terms
    as in their parameter equivalents.
    
    This includes the '@' sign and others in search terms like
    'contact:user at domain.com', which were supported in the contact
    parameter but not in the search parameter before.
    
    Fixes #10972.
---
 CHANGELOG.md                                                      | 2 ++
 src/main/java/org/torproject/onionoo/server/ResourceServlet.java  | 4 ++--
 .../java/org/torproject/onionoo/server/ResourceServletTest.java   | 8 ++++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d457e60..e02f36f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
    - Unify the build process by adding git-submodule metrics-base in
      src/build and removing all centralized parts of the build
      process.
+   - Accept the same characters in qualified search terms as in their
+     parameter equivalents.
 
 
 # Changes in version 3.1-1.0.0 - 2016-11-23
diff --git a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
index 92d0d81..c1c5757 100644
--- a/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
+++ b/src/main/java/org/torproject/onionoo/server/ResourceServlet.java
@@ -362,7 +362,7 @@ public class ResourceServlet extends HttpServlet {
 
   private static Pattern searchQueryStringPattern =
       Pattern.compile("(?:.*[\\?&])*?" // lazily skip other parameters
-          + "search=([0-9a-zA-Z+/\\.: \\$\\[\\]%]+)" // capture parameter
+          + "search=([\\p{Graph} &&[^&]]+)" // capture parameter
           + "(?:&.*)*"); // skip remaining parameters
 
   private static Pattern searchParameterPattern =
@@ -370,7 +370,7 @@ public class ResourceServlet extends HttpServlet {
       + "^[0-9a-zA-Z+/]{1,27}$|" /* Base64 fingerprint. */
       + "^[0-9a-zA-Z\\.]{1,19}$|" /* Nickname or IPv4 address. */
       + "^\\[[0-9a-fA-F:\\.]{1,39}\\]?$|" /* IPv6 address. */
-      + "^[a-zA-Z_]+:[0-9a-zA-Z_,-]+$" /* Qualified search term. */);
+      + "^[a-zA-Z_]+:\\p{Graph}+$" /* Qualified search term. */);
 
   protected static String[] parseSearchParameters(String queryString) {
     Matcher searchQueryStringMatcher = searchQueryStringPattern.matcher(
diff --git a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
index ac466c9..93c3a34 100644
--- a/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
+++ b/src/test/java/org/torproject/onionoo/server/ResourceServletTest.java
@@ -869,6 +869,14 @@ public class ResourceServletTest {
     this.assertErrorStatusCode("/summary?search=limit:1", 400);
   }
 
+
+  @Test()
+  public void testSearchEmailAddress() {
+    this.assertSummaryDocument(
+        "/summary?search=contact:<tor+steven.murdoch at cl.cam.ac.uk>", 1,
+        new String[] { "TimMayTribute" }, 0, null);
+  }
+
   @Test()
   public void testLookupFingerprint() {
     this.assertSummaryDocument(



More information about the tor-commits mailing list