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

[tor-commits] [stem/master] Extrainfo hidden service fields can be negative



commit 60ad8473f5d10e4b354f2b7f182164e1bfdca93a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Mar 16 11:44:48 2015 -0700

    Extrainfo hidden service fields can be negative
    
    Checked with Karsten on #15276.
---
 stem/descriptor/extrainfo_descriptor.py      |    7 ++++---
 test/unit/descriptor/extrainfo_descriptor.py |    7 ++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 228532f..e255320 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -512,10 +512,11 @@ def _parse_hs_stats(keyword, stat_attribute, extra_attribute, descriptor, entrie
 
     if not value_comp:
       raise ValueError("'%s' line was blank" % keyword)
-    elif not value_comp[0].isdigit():
-      raise ValueError("'%s' stat was non-numeric (%s): %s %s" % (keyword, value_comp[0], keyword, value))
 
-    stat = int(value_comp[0])
+    try:
+      stat = int(value_comp[0])
+    except ValueError:
+      raise ValueError("'%s' stat was non-numeric (%s): %s %s" % (keyword, value_comp[0], keyword, value))
 
     for entry in value_comp[1:]:
       if '=' not in entry:
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 6049f50..c418ff3 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -562,7 +562,6 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
 
     test_entries = (
       '',
-      '-50',
       'hello',
       ' key=value',
       '40 key',
@@ -577,6 +576,12 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
       self.assertEqual(345, getattr(desc, stat_attr))
       self.assertEqual({}, getattr(desc, extra_attr))
 
+      # values can be negative (#15276)
+
+      desc = get_relay_extrainfo_descriptor({keyword: '-345'})
+      self.assertEqual(-345, getattr(desc, stat_attr))
+      self.assertEqual({}, getattr(desc, extra_attr))
+
       # with extra attributes
 
       desc = get_relay_extrainfo_descriptor({keyword: '345 spiffy=true snowmen=neat'})

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