Fix `Couldn't parse: falling back to Raw` for empty JSON array (#6619)
#### Description fix #6603 #### Checklist - [x] I have updated tests where applicable. - [ ] I have added an entry to the CHANGELOG. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
6c7089f7a3
commit
1a02ebb89f
|
@ -30,7 +30,12 @@ def is_graphql_query(data):
|
|||
|
||||
|
||||
def is_graphql_batch_query(data):
|
||||
return isinstance(data, list) and isinstance(data[0], dict) and "query" in data[0]
|
||||
return (
|
||||
isinstance(data, list)
|
||||
and len(data) > 0
|
||||
and isinstance(data[0], dict)
|
||||
and "query" in data[0]
|
||||
)
|
||||
|
||||
|
||||
class ViewGraphQL(base.View):
|
||||
|
|
|
@ -19,6 +19,7 @@ def test_render_priority():
|
|||
assert 0 == v.render_priority(
|
||||
b"""[{"xquery": "query P { \\n }"}]""", content_type="application/json"
|
||||
)
|
||||
assert 0 == v.render_priority(b"""[]""", content_type="application/json")
|
||||
assert 0 == v.render_priority(b"}", content_type="application/json")
|
||||
|
||||
|
||||
|
|
|
@ -78,6 +78,22 @@ def test_format_json():
|
|||
[("text", " "), ("text", "]"), ("text", "")],
|
||||
[("text", ""), ("text", "}")],
|
||||
]
|
||||
assert list(json.format_json({"list": []})) == [
|
||||
[("text", "{"), ("text", "")],
|
||||
[
|
||||
("text", " "),
|
||||
("Token_Name_Tag", '"list"'),
|
||||
("text", ": "),
|
||||
("text", "[]"),
|
||||
("text", ""),
|
||||
],
|
||||
[("text", ""), ("text", "}")],
|
||||
]
|
||||
assert list(json.format_json(None)) == [[("Token_Keyword_Constant", "null")]]
|
||||
assert list(json.format_json(True)) == [[("Token_Keyword_Constant", "true")]]
|
||||
assert list(json.format_json(1)) == [[("Token_Literal_Number", "1")]]
|
||||
assert list(json.format_json("test")) == [[("Token_Literal_String", '"test"')]]
|
||||
assert list(json.format_json([])) == [[("text", "[]")]]
|
||||
|
||||
|
||||
def test_view_json():
|
||||
|
@ -88,6 +104,7 @@ def test_view_json():
|
|||
assert v(b"[1, 2, 3, 4, 5]")
|
||||
assert v(b'{"foo" : 3}')
|
||||
assert v(b'{"foo": true, "nullvalue": null}')
|
||||
assert v(b"[]")
|
||||
|
||||
|
||||
@given(binary())
|
||||
|
|
Loading…
Reference in New Issue