File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 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):
8181 """ parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
8282 Quotes can be used to allow commas in the value
8383 """
84- lexer = shlex .shlex (arg )
84+ lexer = shlex .shlex (arg , posix = True )
8585 lexer .wordchars += '/.+-():'
8686
8787 tokens = list (lexer )
@@ -93,7 +93,7 @@ def dict_of_key_value_pairs(arg):
9393 k_eq_v = tokens [i :i + 3 ]
9494 if len (k_eq_v ) != 3 or k_eq_v [1 ] != '=' :
9595 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 ]
9797 i += 4
9898 return D
9999
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):
115115 expected = {'foo' : 'bar,baz' , 'baz' : 'q,ux' }
116116 self .assertEqual (actual , expected )
117117
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+
118133 def test_dict_of_key_value_pairs_handles_unquoted_non_alphanum (self ):
119134 actual = datatypes .dict_of_key_value_pairs (
120135 'HOME=/home/auser,FOO=/.foo+(1.2)-_/,'
You can’t perform that action at this time.
0 commit comments