From f89d98499727bff9e05cc6756463c11f2af5fefb Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Tue, 16 Dec 2014 08:10:38 +0000 Subject: [PATCH] loosened fromcallsign velidation to match aprs.fi --- aprs/parse.py | 12 ++++++--- aprs/version.py | 2 +- tests/test_parse_header.py | 52 ++++++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/aprs/parse.py b/aprs/parse.py index 5d27232..f9f24e5 100644 --- a/aprs/parse.py +++ b/aprs/parse.py @@ -669,10 +669,16 @@ def _parse_header(head): except: raise ParseError("invalid packet header") - if len(fromcall) == 0: - raise ParseError("no fromcallsign in header") + # looking at aprs.fi, the rules for from/src callsign + # are a lot looser, causing a lot of packets to fail + # this check. + # + # if len(fromcall) == 0: + # raise ParseError("no fromcallsign in header") + # _validate_callsign(fromcall, "fromcallsign") - _validate_callsign(fromcall, "fromcallsign") + if not 1 <= len(fromcall) <= 9 or not re.findall(r"^[a-z0-9]{0,9}(\-[a-z0-9]{1,8})?$", fromcall, re.I): + raise ParseError("fromcallsign is invalid") path = path.split(',') diff --git a/aprs/version.py b/aprs/version.py index 0e4f51c..02522d2 100644 --- a/aprs/version.py +++ b/aprs/version.py @@ -1 +1 @@ -__version__ = '0.6.22' +__version__ = '0.6.23' diff --git a/tests/test_parse_header.py b/tests/test_parse_header.py index 29a5d73..0be814e 100644 --- a/tests/test_parse_header.py +++ b/tests/test_parse_header.py @@ -93,13 +93,49 @@ class ParseHeader(unittest.TestCase): self.assertEqual(expected4, result4) + def test_valid_fromcallsigns(self): + testData = [ + "A>CALL", + "4>CALL", + "aaabbbccc>CALL", + "AAABBBCCC>CALL", + "AA1B2BCC9>CALL", + "aa1b2bcc9>CALL", + "-1>CALL", + "-111>CALL", + "-98765432>CALL", + "-a>CALL", + "-abcZZZxx>CALL", + "a-a>CALL", + "a-aaaaaa>CALL", + "callsign1>CALL", + "AAABBB-9>CALL", + "AAABBBC-9>CALL", + "AAABBB-S>CALL", + "AAABBBC-S>CALL", + ] + + for head in testData: + try: + _parse_header(head) + except ParseError, msg: + self.fail("{0}('{1}') PraseError, {2}" + .format(_parse_header.__name__, head, msg)) + def test_invalid_format(self): testData = [ "", # empty header - ">", # empty fromcall - "A>", # empty tocall - "A>b", # invalid tocall - "aaaaaaaaaaa", # invalid fromcall + ">CALL;>test", # empty fromcall + "A>:>test", # empty tocall + "A>-99:>test", # invalid tocall + "aaaAAAaaaA>CALL", # fromcall too long + "->CALL", # invalid fromcall + "A->CALL", # invalid fromcall + "AB->CALL", # invalid fromcall + "ABC->CALL", # invalid fromcall + "9999->CALL", # invalid fromcall + "999aaa11->CALL", # invalid fromcall + "-AAA999AAA>CALL", # invalid fromcall, too long "A>aaaaaaaaaaa", # invalid tocall "A>B,1234567890,C", # invalid call in path "A>B,C,1234567890,D", # invalid call in path @@ -107,7 +143,13 @@ class ParseHeader(unittest.TestCase): ] for head in testData: - self.assertRaises(ParseError, _parse_header, head) + try: + _parse_header(head) + self.fail("{0} didn't raise exception for: {1}" + .format(_parse_header.__name__, head)) + except ParseError: + continue + if __name__ == '__main__': unittest.main()