Skip to content

Commit

Permalink
Make sure all control characters are quoted.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Oct 11, 2021
1 parent 0b4913d commit d1ba3b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions plugins/module_utils/quoting.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def quote_routeros_argument_value(argument):
result.append(b'\\%s' % ESCAPE_SEQUENCE_REVERSED[letter])
quote = True
continue
elif ord(letter) < 32:
v = ord(letter)
v1 = v % 16
v2 = v // 16
result.append(b'\\%s%s' % (ESCAPE_DIGITS[v2:v2 + 1], ESCAPE_DIGITS[v1:v1 + 1]))
quote = True
continue
elif letter in (b' ', b'=', b';', b"'"):
quote = True
result.append(letter)
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/plugins/module_utils/test_quoting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
('a ', {'must_match_everything': False}, ('a', 1)),
(r'"a b"', {}, ('a b', 5)),
(r'"b\"f"', {}, ('b"f', 6)),
(r'"\01"', {}, ('\x01', 5)),
(r'"\1F"', {}, ('\x1f', 5)),
(r'"\FF"', {}, (to_native(b'\xff'), 5)),
(r'"\"e"', {}, ('"e', 5)),
(r'"\""', {}, ('"', 4)),
Expand Down Expand Up @@ -225,11 +227,13 @@ def test_quote_routeros_argument_errors(argument, message):
('_', r'"\_"'),
('\a', r'"\a"'),
('\b', r'"\b"'),
# (to_native('\xff'), r'"\f"'),
# (to_native(b'\xff'), r'"\f"'),
('\n', r'"\n"'),
('\r', r'"\r"'),
('\t', r'"\t"'),
('\v', r'"\v"'),
('\x01', r'"\01"'),
('\x1f', r'"\1F"'),
]


Expand Down

0 comments on commit d1ba3b2

Please sign in to comment.