[onionoo/master] Fix nickname search for bridges.

commit 04a1db13349344b3d6acd069d4b7f11024adade9 Author: Karsten Loesing <karsten.loesing@gmx.net> Date: Thu Jun 14 14:18:26 2012 +0200 Fix nickname search for bridges. --- src/org/torproject/onionoo/ResourceServlet.java | 27 ++++++++++++++++++---- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java index e4f5b9f..4f1749d 100644 --- a/src/org/torproject/onionoo/ResourceServlet.java +++ b/src/org/torproject/onionoo/ResourceServlet.java @@ -475,7 +475,7 @@ public class ResourceServlet extends HttpServlet { /* Nickname matches. */ lineMatches = true; } else if ("unnamed".startsWith(searchTerm.toLowerCase()) && - (line.startsWith("{\"f\":") || line.startsWith("{\"h\":"))) { + line.startsWith("{\"f\":")) { /* Nickname "Unnamed" matches. */ lineMatches = true; } else if (line.contains("\"f\":\"" + searchTerm.toUpperCase())) { @@ -494,12 +494,29 @@ public class ResourceServlet extends HttpServlet { filteredRelays.remove(fingerprint); } Set<String> removeBridges = new HashSet<String>(); - if (searchTerm.startsWith("$")) { - searchTerm = searchTerm.substring(1); - } for (Map.Entry<String, String> e : filteredBridges.entrySet()) { String line = e.getValue(); - if (!line.contains("\"h\":\"" + searchTerm.toUpperCase())) { + boolean lineMatches = false; + if (searchTerm.startsWith("$")) { + /* Search is for $-prefixed hashed fingerprint. */ + if (line.contains("\"h\":\"" + + searchTerm.substring(1).toUpperCase())) { + /* $-prefixed hashed fingerprint matches. */ + lineMatches = true; + } + } else if (line.toLowerCase().contains("\"n\":\"" + + searchTerm.toLowerCase())) { + /* Nickname matches. */ + lineMatches = true; + } else if ("unnamed".startsWith(searchTerm.toLowerCase()) && + line.startsWith("{\"h\":")) { + /* Nickname "Unnamed" matches. */ + lineMatches = true; + } else if (line.contains("\"h\":\"" + searchTerm.toUpperCase())) { + /* Non-$-prefixed hashed fingerprint matches. */ + lineMatches = true; + } + if (!lineMatches) { removeBridges.add(e.getKey()); } }
participants (1)
-
karsten@torproject.org