Skip to content

Commit

Permalink
Inching forward
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Apr 1, 2024
1 parent 8ae396d commit 97b2d67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pywb/warcserver/inputrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
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 @@ -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]}'
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 97b2d67

Please sign in to comment.