File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ def dict_of_key_value_pairs(arg):
81
81
""" parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
82
82
Quotes can be used to allow commas in the value
83
83
"""
84
- lexer = shlex .shlex (arg )
84
+ lexer = shlex .shlex (arg , posix = True )
85
85
lexer .wordchars += '/.+-():'
86
86
87
87
tokens = list (lexer )
@@ -93,7 +93,7 @@ def dict_of_key_value_pairs(arg):
93
93
k_eq_v = tokens [i :i + 3 ]
94
94
if len (k_eq_v ) != 3 or k_eq_v [1 ] != '=' :
95
95
raise ValueError ("Unexpected end of key/value pairs" )
96
- D [k_eq_v [0 ]] = k_eq_v [2 ]. strip ( ' \' "' )
96
+ D [k_eq_v [0 ]] = k_eq_v [2 ]
97
97
i += 4
98
98
return D
99
99
Original file line number Diff line number Diff line change @@ -115,6 +115,21 @@ def test_dict_of_key_value_pairs_handles_commas_inside_quotes(self):
115
115
expected = {'foo' : 'bar,baz' , 'baz' : 'q,ux' }
116
116
self .assertEqual (actual , expected )
117
117
118
+ def test_dict_of_key_value_pairs_handles_newlines_inside_quotes (self ):
119
+ actual = datatypes .dict_of_key_value_pairs ('foo="a\n b\n c"' )
120
+ expected = {'foo' : 'a\n b\n c' }
121
+ self .assertEqual (actual , expected )
122
+
123
+ def test_dict_of_key_value_pairs_handles_quotes_inside_quotes (self ):
124
+ actual = datatypes .dict_of_key_value_pairs ('foo="\' \\ ""' )
125
+ expected = {'foo' : '\' "' }
126
+ self .assertEqual (actual , expected )
127
+
128
+ def test_dict_of_key_value_pairs_handles_empty_inside_quotes (self ):
129
+ actual = datatypes .dict_of_key_value_pairs ('foo=""' )
130
+ expected = {'foo' : '' }
131
+ self .assertEqual (actual , expected )
132
+
118
133
def test_dict_of_key_value_pairs_handles_unquoted_non_alphanum (self ):
119
134
actual = datatypes .dict_of_key_value_pairs (
120
135
'HOME=/home/auser,FOO=/.foo+(1.2)-_/,'
You can’t perform that action at this time.
0 commit comments