diff --git a/snmpsim/grammar/snmprec.py b/snmpsim/grammar/snmprec.py index afb0283..dafcabe 100644 --- a/snmpsim/grammar/snmprec.py +++ b/snmpsim/grammar/snmprec.py @@ -46,14 +46,14 @@ def build(self, oid, tag, val): def parse(self, line): try: - oid, tag, value = line.decode("iso-8859-1").strip().split("|", 2) + oid, tag, value = line.decode("iso-8859-1").split("|", 2) except Exception as exc: raise error.SnmpsimError(f"broken record <{line}>: {exc}") else: if oid and tag: - return oid, tag, value + return oid.strip(), tag.strip(), value.strip("\r\n\t") raise error.SnmpsimError("broken record <%s>" % line) diff --git a/tests/test_snmprec_grammar.py b/tests/test_snmprec_grammar.py new file mode 100644 index 0000000..3eb6329 --- /dev/null +++ b/tests/test_snmprec_grammar.py @@ -0,0 +1,12 @@ +from snmpsim.record.snmprec import SnmprecRecord + + +def test_escaped_value_preserves_trailing_space(): + record = SnmprecRecord() + + oid, value = record.evaluate( + b"1.3.6.1.2.1.3.1.1.3.3.1.85.209.202.32|64e|U\\xd1\\xca \n" + ) + + assert oid.prettyPrint() == "1.3.6.1.2.1.3.1.1.3.3.1.85.209.202.32" + assert list(value) == [85, 209, 202, 32]