Skip to content

Commit

Permalink
Fix: ConfigParser incorrectly parses tokens with ' character
Browse files Browse the repository at this point in the history
  • Loading branch information
remip2 committed Jun 15, 2021
1 parent 7e2f8ce commit dc8875c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion stormshield/sns/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def __init__(self, text):
line = line.encode('utf-8')
# parse token=value token2=value2
lexer = shlex(line, posix=True)
lexer.wordchars += "=.-*:,/@"
lexer.wordchars += "=.-*:,/@'"
lexer.quotes = '"'
parsed = {}
for word in lexer:
# ignore anything else than token=value
Expand Down
2 changes: 1 addition & 1 deletion stormshield/sns/sslclient/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# major: breaking API change
# minor: new functionality
# patch: bugfix
__version__ = "1.0.3"
__version__ = "1.0.4"
14 changes: 14 additions & 0 deletions tests/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ def test_arobase_in_value(self):
config = ConfigParser(input)
self.assertEqual(expected, config.data)

def test_quote_in_token(self):
""" Test parsing of token with ' character """

input = """101 code=00a01000 msg="Begin" format="section_line"
[Object]
type=group global=0 name=it's_a_test nb_elements=2 modify=1 comment= used=0
100 code=00a00100 msg="Ok"\""""

expected = {"Object": [
{"type":"group", "global":"0", "name":"it's_a_test",
"nb_elements":"2", "modify":"1", "comment":"", "used":"0"}]}

config = ConfigParser(input)
self.assertEqual(expected, config.data)

if __name__ == '__main__':
unittest.main()

0 comments on commit dc8875c

Please sign in to comment.