@@ -92,13 +92,20 @@ def __call__(self, s: str) -> KeyValueArg:
9292 # Starting first, longest separator found.
9393 sep = found [min (found .keys ())]
9494
95- key , value = token .split (sep , 1 )
95+ key_part , value_part = token .split (sep , 1 )
9696
97- # Any preceding tokens are part of the key.
98- key = '' .join (tokens [:i ]) + key
97+ # The key is composed of:
98+ # 1. Any preceding tokens (unescaped by str(t) in join)
99+ # 2. The key part of the current token (re-tokenize to
100+ # handle internal escapes correctly)
101+ key_tokens = tokens [:i ] + self .tokenize (key_part )
102+ key = '' .join (str (t ) for t in key_tokens )
99103
100- # Any following tokens are part of the value.
101- value += '' .join (tokens [i + 1 :])
104+ # The value is composed of:
105+ # 1. The value part of the current token (re-tokenize)
106+ # 2. Any succeeding tokens (unescaped by str(t) in join)
107+ value_tokens = self .tokenize (value_part ) + tokens [i + 1 :]
108+ value = '' .join (str (t ) for t in value_tokens )
102109
103110 break
104111
@@ -272,4 +279,4 @@ def response_mime_type(mime_type: str) -> str:
272279 if mime_type .count ('/' ) != 1 :
273280 raise argparse .ArgumentTypeError (
274281 f'{ mime_type !r} doesn’t look like a mime type; use type/subtype' )
275- return mime_type
282+ return mime_type
0 commit comments