Skip to content

Commit

Permalink
Getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Apr 1, 2024
1 parent ea97998 commit 8ae396d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pywb/warcserver/inputrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,13 @@ 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 = ''

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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pywb/warcserver/test/test_inputreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 8ae396d

Please sign in to comment.