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

[code_review] JSONDecodeError: Invalid \escape in searchfox_api #4448

Closed
suhaibmujahid opened this issue Aug 28, 2024 · 0 comments · Fixed by #4449
Closed

[code_review] JSONDecodeError: Invalid \escape in searchfox_api #4448

suhaibmujahid opened this issue Aug 28, 2024 · 0 comments · Fixed by #4449
Assignees
Labels
bug Something isn't working code-review

Comments

@suhaibmujahid
Copy link
Member

suhaibmujahid commented Aug 28, 2024

Exception has occurred: JSONDecodeError       (note: full exception trace is shown but execution is paused at: run)
Invalid \escape: line 1 column 386341 (char 386340)
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/code_search/searchfox_api.py", line 92, in search
    results = json.loads(after_results[: after_results.index(";\n")])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/code_search/searchfox_api.py", line 160, in get_function_by_name
    definitions = search(
                  ^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/code_search/mozilla.py", line 55, in get_function
    result = function_search_searchfox_api.get_function_by_name(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/code_search/mozilla.py", line 79, in get_function_by_name
    return self.get_function(
           ^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/tools/code_review.py", line 807, in request_for_function_declarations
    definitions = function_search.get_function_by_name(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/bugbug/tools/code_review.py", line 1052, in run (Current frame)
    requested_functions = request_for_function_declarations(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/smujahid/repos/mozilla/bugbug/venv/lib/python3.11/site-packages/tenacity/__init__.py", line 478, in __call__
    result = fn(*args, **kwargs)
  File "/Users/smujahid/repos/mozilla/bugbug/venv/lib/python3.11/site-packages/tenacity/__init__.py", line 336, in wrapped_f
    return copy(f, *args, **kw)
  File "/Users/smujahid/repos/mozilla/bugbug/scripts/code_review_tool_evaluator.py", line 194, in main
    comments = tool.run(patch)
  File "/Users/smujahid/repos/mozilla/bugbug/scripts/code_review_tool_evaluator.py", line 253, in <module>
    main(args.variants, args.review_request_ids)
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 386341 (char 386340)

This occurs when loading a JSON string with the following (the position 386341 is the s in \\"<\\script>\\"):

{"lno": 464, "bounds": [7, 11], "line": "return{send:function(r,i){t=de(\"<\script>\").prop({charset:e.scriptCharset,src:e.url}).on(\"load error\"", "context": "", "contextsym": ""}

MRE:

import json

json.loads('["<\\script>"]')
# or
json.loads(r'["<\script>"]')

Here is the page that we are trying to parse its content: https://searchfox.org/mozilla-central/search?q=send

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code-review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant