Fix for JSON array parsing in multipart/form-data (#1869) (#1872)

Fixes #1869 .



Changes proposed in this pull request:

- Prioritise parsing JSON over splitting array

---------

Co-authored-by: Alex Fechner <alex.fechner@stryker.com>
This commit is contained in:
alfechner
2024-02-13 23:01:10 +01:00
committed by GitHub
parent 5d7eb0bdab
commit 5de6dccfbb
4 changed files with 64 additions and 3 deletions

View File

@@ -128,3 +128,27 @@ def test_multipart_form_json(json_validation_spec_dir, spec, app_class):
assert res.status_code == 200
assert res.json()["name"] == "joe-reply"
assert res.json()["age"] == 30
@pytest.mark.parametrize("spec", ["openapi.yaml"])
def test_multipart_form_json_array(json_validation_spec_dir, spec, app_class):
app = build_app_from_fixture(
json_validation_spec_dir,
app_class=app_class,
spec_file=spec,
validate_responses=True,
)
app_client = app.test_client()
res = app_client.post(
"/v1.0/multipart_form_json_array",
files={"file": b""}, # Force multipart/form-data content-type
data={
"x": json.dumps([{"name": "joe", "age": 20}, {"name": "alena", "age": 28}])
},
)
assert res.status_code == 200
assert res.json()[0]["name"] == "joe-reply"
assert res.json()[0]["age"] == 30
assert res.json()[1]["name"] == "alena-reply"
assert res.json()[1]["age"] == 38