Correctly handle \_ escape sequence. (#89)

This commit is contained in:
Felix Fontein 2022-05-09 22:09:08 +02:00 committed by GitHub
parent 02ecc0ca9d
commit a90c696589
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 15 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "quoting and unquoting filter plugins, api module - handle the escape sequence ``\\_`` correctly as escaping a space and not an underscore (https://github.com/ansible-collections/community.routeros/pull/89)."

View file

@ -21,7 +21,7 @@ ESCAPE_SEQUENCES = {
b'\\': b'\\', b'\\': b'\\',
b'?': b'?', b'?': b'?',
b'$': b'$', b'$': b'$',
b'_': b'_', b'_': b' ',
b'a': b'\a', b'a': b'\a',
b'b': b'\b', b'b': b'\b',
b'f': b'\xFF', b'f': b'\xFF',

View file

@ -28,7 +28,7 @@
- > - >
'a=b' | community.routeros.quote_argument == 'a=b' 'a=b' | community.routeros.quote_argument == 'a=b'
- > - >
'a=b c' | community.routeros.quote_argument == 'a="b c"' 'a=b c' | community.routeros.quote_argument == 'a="b\\_c"'
- > - >
'a=""' | community.routeros.quote_argument == 'a="\\"\\""' 'a=""' | community.routeros.quote_argument == 'a="\\"\\""'
@ -40,13 +40,13 @@
- > - >
'foo' | community.routeros.quote_argument_value == 'foo' 'foo' | community.routeros.quote_argument_value == 'foo'
- > - >
'"foo bar"' | community.routeros.quote_argument_value == '"\\"foo bar\\""' '"foo bar"' | community.routeros.quote_argument_value == '"\\"foo\\_bar\\""'
- name: "Test join filter" - name: "Test join filter"
assert: assert:
that: that:
- > - >
['a=', 'b=c d'] | community.routeros.join == 'a="" b="c d"' ['a=', 'b=c d'] | community.routeros.join == 'a="" b="c\\_d"'
- name: "Test list_to_dict filter" - name: "Test list_to_dict filter"
assert: assert:

View file

@ -28,7 +28,7 @@
- > - >
'a=b' | community.routeros.quote_argument == 'a=b' 'a=b' | community.routeros.quote_argument == 'a=b'
- > - >
'a=b c' | community.routeros.quote_argument == 'a="b c"' 'a=b c' | community.routeros.quote_argument == 'a="b\\_c"'
- > - >
'a=""' | community.routeros.quote_argument == 'a="\\"\\""' 'a=""' | community.routeros.quote_argument == 'a="\\"\\""'
@ -40,13 +40,13 @@
- > - >
'foo' | community.routeros.quote_argument_value == 'foo' 'foo' | community.routeros.quote_argument_value == 'foo'
- > - >
'"foo bar"' | community.routeros.quote_argument_value == '"\\"foo bar\\""' '"foo bar"' | community.routeros.quote_argument_value == '"\\"foo\\_bar\\""'
- name: "Test join filter" - name: "Test join filter"
assert: assert:
that: that:
- > - >
['a=', 'b=c d'] | community.routeros.join == 'a="" b="c d"' ['a=', 'b=c d'] | community.routeros.join == 'a="" b="c\\_d"'
- name: "Test list_to_dict filter" - name: "Test list_to_dict filter"
assert: assert:

View file

@ -34,7 +34,7 @@ TEST_PARSE_ARGUMENT_VALUE = [
(r'"\\"', {}, ('\\', 4)), (r'"\\"', {}, ('\\', 4)),
(r'"\?"', {}, ('?', 4)), (r'"\?"', {}, ('?', 4)),
(r'"\$"', {}, ('$', 4)), (r'"\$"', {}, ('$', 4)),
(r'"\_"', {}, ('_', 4)), (r'"\_"', {}, (' ', 4)),
(r'"\a"', {}, ('\a', 4)), (r'"\a"', {}, ('\a', 4)),
(r'"\b"', {}, ('\b', 4)), (r'"\b"', {}, ('\b', 4)),
(r'"\f"', {}, (to_native(b'\xff'), 4)), (r'"\f"', {}, (to_native(b'\xff'), 4)),
@ -165,7 +165,7 @@ def test_convert_list_to_dictionary_errors(list, kwargs, message):
TEST_JOIN_ROUTEROS_COMMAND = [ TEST_JOIN_ROUTEROS_COMMAND = [
(['a=b', 'c=d=e', 'e=', 'f', 'g=h i j', 'h="h"'], r'a=b c="d=e" e="" f g="h i j" h="\"h\""'), (['a=b', 'c=d=e', 'e=', 'f', 'g=h i j', 'h="h"'], r'a=b c="d=e" e="" f g="h\_i\_j" h="\"h\""'),
] ]
@ -180,8 +180,8 @@ TEST_QUOTE_ROUTEROS_ARGUMENT = [
(r'', r''), (r'', r''),
(r'a', r'a'), (r'a', r'a'),
(r'a=b', r'a=b'), (r'a=b', r'a=b'),
(r'a=b c', r'a="b c"'), (r'a=b c', r'a="b\_c"'),
(r'a="b c"', r'a="\"b c\""'), (r'a="b c"', r'a="\"b\_c\""'),
(r"a='b", "a=\"'b\""), (r"a='b", "a=\"'b\""),
(r"a=b'", "a=\"b'\""), (r"a=b'", "a=\"b'\""),
(r'a=""', r'a="\"\""'), (r'a=""', r'a="\"\""'),
@ -212,19 +212,20 @@ def test_quote_routeros_argument_errors(argument, message):
TEST_QUOTE_ROUTEROS_ARGUMENT_VALUE = [ TEST_QUOTE_ROUTEROS_ARGUMENT_VALUE = [
(r'', r'""'), (r'', r'""'),
(r";", r'";"'), (r";", r'";"'),
(r" ", r'" "'), (r" ", r'"\_"'),
(r"=", r'"="'), (r"=", r'"="'),
(r'a', r'a'), (r'a', r'a'),
(r'a=b', r'"a=b"'), (r'a=b', r'"a=b"'),
(r'b c', r'"b c"'), (r'b c', r'"b\_c"'),
(r'"b c"', r'"\"b c\""'), (r'"b c"', r'"\"b\_c\""'),
("'b", "\"'b\""), ("'b", "\"'b\""),
("b'", "\"b'\""), ("b'", "\"b'\""),
('"', r'"\""'), ('"', r'"\""'),
('\\', r'"\\"'), ('\\', r'"\\"'),
('?', r'"\?"'), ('?', r'"\?"'),
('$', r'"\$"'), ('$', r'"\$"'),
('_', r'"\_"'), ('_', r'_'),
(' ', r'"\_"'),
('\a', r'"\a"'), ('\a', r'"\a"'),
('\b', r'"\b"'), ('\b', r'"\b"'),
# (to_native(b'\xff'), r'"\f"'), # (to_native(b'\xff'), r'"\f"'),