Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post query json parse fix #711

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pywb 2.6.7 changelist

* dependency: bump gevent to latest (21.12.0)
* rewrite: fix eval rewriting where '._eval' was accidentally being rewritten
* post-to-get conversion: properly handle json with top-level lists, to match cdxj-indexer, print parse errors, fixes `#709 <https://github.com/webrecorder/pywb/pull/709>`_

pywb 2.6.6 changelist
~~~~~~~~~~~~~~~~~~~~~
Expand Down
19 changes: 13 additions & 6 deletions pywb/warcserver/inputrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import base64
import cgi
import json
import sys


#=============================================================================
Expand Down Expand Up @@ -277,6 +278,7 @@ def handle_binary(query):
try:
query = self.json_parse(query)
except Exception as e:
sys.stderr.write("Ignoring query, error parsing as json: " + query.decode("utf-8") + "\n")
query = ''

elif mime.startswith('text/plain'):
Expand Down Expand Up @@ -316,12 +318,17 @@ def get_key(n):
dupes[n] += 1
return n + "." + str(dupes[n]) + "_";

def _parser(dict_var):
for n, v in dict_var.items():
if isinstance(v, dict):
_parser(v)
else:
data[get_key(n)] = str(v)
def _parser(json_obj, name=""):
if isinstance(json_obj, dict):
for n, v in json_obj.items():
_parser(v, n)

elif isinstance(json_obj, list):
for v in json_obj:
_parser(v, name)

elif name:
data[get_key(name)] = str(json_obj)

_parser(json.loads(string))
return urlencode(data)
Expand Down