[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Handle non-positive offsets and limits.



commit b4b90b045c1ef257d08951954bb44ec59aec909f
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Thu Dec 6 09:09:55 2012 +0100

    Handle non-positive offsets and limits.
    
    Non-positive offsets were previously ignored, which is still the case.
    
    However, non-positive limits were ignored, too, which seems wrong.  If
    a client wants even less than none documents, we shouldn't respond with
    all documents we have.  Instead, we should return an empty response.
---
 src/org/torproject/onionoo/ResourceServlet.java |   12 ++++--------
 web/index.html                                  |    4 ++++
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index bc075b0..0fa9174 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -330,16 +330,12 @@ public class ResourceServlet extends HttpServlet {
         response.sendError(HttpServletResponse.SC_BAD_REQUEST);
         return;
       }
-      if (limit >= 0) {
-        while (limit < orderedRelays.size()) {
-          orderedRelays.remove(orderedRelays.size() - 1);
-        }
+      while (!orderedRelays.isEmpty() && limit < orderedRelays.size()) {
+        orderedRelays.remove(orderedRelays.size() - 1);
       }
       limit -= orderedRelays.size();
-      if (limit >= 0) {
-        while (limit < orderedBridges.size()) {
-          orderedBridges.remove(orderedBridges.size() - 1);
-        }
+      while (!orderedBridges.isEmpty() && limit < orderedBridges.size()) {
+        orderedBridges.remove(orderedBridges.size() - 1);
       }
     }
 
diff --git a/web/index.html b/web/index.html
index e29c0b8..ca87016 100755
--- a/web/index.html
+++ b/web/index.html
@@ -684,10 +684,14 @@ undefined.
 <tr><td><b>offset</b></td><td>Skip the given number of relays and/or
 bridges.
 Relays are skipped first, then bridges.
+Non-positive <b>offset</b> values are treated as zero and don't change the
+result.
 </td></tr>
 <tr><td><b>limit</b></td><td>Limit result to the given number of
 relays and/or bridges.
 Relays are kept first, then bridges.
+Non-positive <b>limit</b> values are treated as zero and lead to an empty
+result.
 When used together with <b>offset</b>, the offsetting step precedes the
 limiting step.
 </td></tr>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits