diff options
| author | Damian Johnson <atagar@torproject.org> | 2015-03-16 11:44:48 -0700 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2015-03-16 11:44:48 -0700 |
| commit | 60ad8473f5d10e4b354f2b7f182164e1bfdca93a (patch) | |
| tree | 4326a9f7e36c9ba670f076a434c2fe2b2159faf9 | |
| parent | 4ad8f60e2622e1ae5a7a46d131350c8042f02d66 (diff) | |
Extrainfo hidden service fields can be negative
Checked with Karsten on #15276.
| -rw-r--r-- | stem/descriptor/extrainfo_descriptor.py | 7 | ||||
| -rw-r--r-- | 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 228532ff..e255320f 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 6049f502..c418ff39 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'}) |
