File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,10 @@ def test_to_dict(self) -> None:
150
150
self .assertDictEqual ({"FOO" : "v1,v2" }, to_dict ("FOO=v1,v2" ))
151
151
self .assertDictEqual ({"FOO" : "v1;v2" }, to_dict ("FOO=v1;v2" ))
152
152
153
+ # Handles empty strings as a special case
154
+ self .assertDictEqual ({"FOO" : "" }, to_dict ("FOO=''" ))
155
+ self .assertDictEqual ({"FOO" : "" }, to_dict ('FOO=""' ))
156
+
153
157
# trailing delimiters preserved
154
158
# a delim without the next key should be interpreted as the value for FOO
155
159
self .assertDictEqual ({"FOO" : "," }, to_dict ("FOO=," ))
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ def to_dict(arg: str) -> Dict[str, str]:
45
45
46
46
to_dict("FOO=v1") == {"FOO": "v1"}
47
47
48
+ to_dict("FOO=''") == {"FOO": ""}
49
+ to_dict('FOO=""') == {"FOO": ""}
50
+
48
51
to_dict("FOO=v1,v2") == {"FOO": "v1,v2"]}
49
52
to_dict("FOO=v1;v2") == {"FOO": "v1;v2"]}
50
53
to_dict("FOO=v1;v2") == {"FOO": "v1;v2,"]}
@@ -70,6 +73,9 @@ def parse_val_key(vk: str) -> Tuple[str, str]:
70
73
else :
71
74
return vk [0 :idx ].strip (), vk [idx + 1 :].strip ()
72
75
76
+ def to_val (val : str ) -> str :
77
+ return val if val != '""' and val != "''" else ""
78
+
73
79
arg_map : Dict [str , str ] = {}
74
80
75
81
if not arg :
@@ -92,10 +98,10 @@ def parse_val_key(vk: str) -> Tuple[str, str]:
92
98
# middle elements are value_{n}<delim>key_{n+1}
93
99
for vk in split_arg [1 : split_arg_len - 1 ]: # python deals with
94
100
val , key_next = parse_val_key (vk )
95
- arg_map [key ] = val
101
+ arg_map [key ] = to_val ( val )
96
102
key = key_next
97
103
val = split_arg [- 1 ] # last element is always a value
98
- arg_map [key ] = val
104
+ arg_map [key ] = to_val ( val )
99
105
return arg_map
100
106
101
107
You can’t perform that action at this time.
0 commit comments