Skip to content

Commit dc8875c

Browse files
committed
Fix: ConfigParser incorrectly parses tokens with ' character
1 parent 7e2f8ce commit dc8875c

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

stormshield/sns/configparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def __init__(self, text):
9494
line = line.encode('utf-8')
9595
# parse token=value token2=value2
9696
lexer = shlex(line, posix=True)
97-
lexer.wordchars += "=.-*:,/@"
97+
lexer.wordchars += "=.-*:,/@'"
98+
lexer.quotes = '"'
9899
parsed = {}
99100
for word in lexer:
100101
# ignore anything else than token=value

stormshield/sns/sslclient/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# major: breaking API change
33
# minor: new functionality
44
# patch: bugfix
5-
__version__ = "1.0.3"
5+
__version__ = "1.0.4"

tests/test_configparser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ def test_arobase_in_value(self):
202202
config = ConfigParser(input)
203203
self.assertEqual(expected, config.data)
204204

205+
def test_quote_in_token(self):
206+
""" Test parsing of token with ' character """
207+
208+
input = """101 code=00a01000 msg="Begin" format="section_line"
209+
[Object]
210+
type=group global=0 name=it's_a_test nb_elements=2 modify=1 comment= used=0
211+
100 code=00a00100 msg="Ok"\""""
212+
213+
expected = {"Object": [
214+
{"type":"group", "global":"0", "name":"it's_a_test",
215+
"nb_elements":"2", "modify":"1", "comment":"", "used":"0"}]}
216+
217+
config = ConfigParser(input)
218+
self.assertEqual(expected, config.data)
205219

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

0 commit comments

Comments
 (0)