diff --git a/pywb/warcserver/inputrequest.py b/pywb/warcserver/inputrequest.py index 081f801c..fb795221 100644 --- a/pywb/warcserver/inputrequest.py +++ b/pywb/warcserver/inputrequest.py @@ -240,11 +240,12 @@ def handle_binary(query): query = '__wb_post_data=' + query return query + # TODO: Forms keeps JSON values but doesn't account for multiple values + # with same name if mime.startswith('application/x-www-form-urlencoded'): try: query = to_native_str(query.decode('utf-8')) query = unquote_plus(query) - # TODO: Convert Pythonic values to JSON values except UnicodeDecodeError: query = handle_binary(query) @@ -331,11 +332,11 @@ def _parser(json_obj, name=""): _parser(v, name) elif name: - if isinstance(name, bool) and name: + if (isinstance(name, bool) and name) or name == "True": data[get_key(name)] = "true" - elif isinstance(name, bool): + elif isinstance(name, bool) or name == "False": data[get_key(name)] = "false" - elif name is None: + elif name in ("None", None): data[get_key(name)] = "null" else: data[get_key(name)] = str(json_obj) diff --git a/pywb/warcserver/test/test_inputreq.py b/pywb/warcserver/test/test_inputreq.py index c10af574..5d4b4334 100644 --- a/pywb/warcserver/test/test_inputreq.py +++ b/pywb/warcserver/test/test_inputreq.py @@ -91,7 +91,7 @@ def test_post_extract_1(self): assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=POST&foo=bar&dir=/baz&do=true&re=false&re.2=null' - assert mq.append_query('http://example.com/?123=ABC') == 'http://example.com/?123=ABC&__wb_method=POST&foo=bar&dir=/baz&do=true&re=false&re.1=null' + assert mq.append_query('http://example.com/?123=ABC') == 'http://example.com/?123=ABC&__wb_method=POST&foo=bar&dir=/baz&do=true&re=false&re.2=null' def test_post_extract_json(self): post_data = b'{"a": "b", "c": {"a": 2}, "d": "e", "f": true, "g": [false, null]}' @@ -155,7 +155,7 @@ def test_post_extract_no_boundary_in_multipart_form_mimetype(self): mq = MethodQueryCanonicalizer('POST', 'multipart/form-data', len(self.post_data), BytesIO(self.post_data)) - assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=POST&__wb_post_data=gTZsYEygNFAO4HICtYkZAGZQ2w6wAiw=' + assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=POST&__wb_post_data=Zm9vPWJhciZkaXI9JTJGYmF6JmRvPXRydWUmcmU9ZmFsc2UmcmU9bnVsbA==' def test_options(self):