Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions snmpsim/grammar/snmprec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_snmprec_grammar.py
Original file line number Diff line number Diff line change
@@ -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]