diff --git a/pywb/warcserver/inputrequest.py b/pywb/warcserver/inputrequest.py index 6b6a441c..081f801c 100644 --- a/pywb/warcserver/inputrequest.py +++ b/pywb/warcserver/inputrequest.py @@ -280,7 +280,6 @@ def handle_binary(query): elif mime.startswith('application/json'): try: query = self.json_parse(query) - # TODO: Convert Pythonic values to JSON values except Exception as e: sys.stderr.write("Ignoring query, error parsing as json: " + query.decode("utf-8") + "\n") query = '' @@ -288,7 +287,6 @@ def handle_binary(query): elif mime.startswith('text/plain'): try: query = self.json_parse(query) - # TODO: Convert Pythonic values to JSON values except Exception as e: query = handle_binary(query) @@ -333,7 +331,14 @@ def _parser(json_obj, name=""): _parser(v, name) elif name: - data[get_key(name)] = json.dumps(json_obj) + if isinstance(name, bool) and name: + data[get_key(name)] = "true" + elif isinstance(name, bool): + data[get_key(name)] = "false" + elif name is None: + data[get_key(name)] = "null" + else: + data[get_key(name)] = str(json_obj) _parser(json.loads(string)) return urlencode(data) diff --git a/pywb/warcserver/test/test_inputreq.py b/pywb/warcserver/test/test_inputreq.py index d4e957b5..c10af574 100644 --- a/pywb/warcserver/test/test_inputreq.py +++ b/pywb/warcserver/test/test_inputreq.py @@ -105,7 +105,7 @@ def test_put_extract_method(self): mq = MethodQueryCanonicalizer('PUT', 'application/x-www-form-urlencoded', len(self.post_data), BytesIO(self.post_data)) - assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=PUT&foo=bar&dir=/baz&do=true&re=false&re.2=null' + assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=PUT&foo=bar&dir=/baz&do=true&re=false&re=null' def test_post_extract_non_form_data_1(self): mq = MethodQueryCanonicalizer('POST', 'application/octet-stream', @@ -136,7 +136,7 @@ def test_post_extract_length_too_short(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded', len(self.post_data) - 4, BytesIO(self.post_data)) - assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=POST&foo=bar&dir=%2&do=true&re=false' + assert mq.append_query('http://example.com/') == 'http://example.com/?__wb_method=POST&foo=bar&dir=%2&do=true&re=' def test_post_extract_length_too_long(self): mq = MethodQueryCanonicalizer('POST', 'application/x-www-form-urlencoded',