diff --git a/CHANGES.rst b/CHANGES.rst index bb9770aba..88970a666 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,10 +6,11 @@ Version 2.3.7 Unreleased - Use ``flit_core`` instead of ``setuptools`` as build backend. -- Fix parsing of multipart bodies. +- Fix parsing of multipart bodies. :issue:`2734` Adjust index of last newline in data start. :issue:`2761` - ``_plain_int`` and ``_plain_float`` strip whitespace before type enforcement. :issue:`2734` +- Fix empty file streaming when testing. :issue:`2740` Version 2.3.6 diff --git a/src/werkzeug/test.py b/src/werkzeug/test.py index f5b4f2ff7..968553f2b 100644 --- a/src/werkzeug/test.py +++ b/src/werkzeug/test.py @@ -136,6 +136,7 @@ def write_binary(s: bytes) -> int: chunk = reader(16384) if not chunk: + write_binary(encoder.send_event(Data(data=chunk, more_data=False))) break write_binary(encoder.send_event(Data(data=chunk, more_data=True))) diff --git a/tests/test_test.py b/tests/test_test.py index a73900086..c7f21fa11 100644 --- a/tests/test_test.py +++ b/tests/test_test.py @@ -357,6 +357,23 @@ def test_environ_builder_unicode_file_mix(): files["f"].close() +def test_environ_builder_empty_file(): + f = FileStorage(BytesIO(rb""), "empty.txt") + d = MultiDict(dict(f=f, s="")) + stream, length, boundary = stream_encode_multipart(d) + _, form, files = parse_form_data( + { + "wsgi.input": stream, + "CONTENT_LENGTH": str(length), + "CONTENT_TYPE": f'multipart/form-data; boundary="{boundary}"', + } + ) + assert form["s"] == "" + assert files["f"].read() == rb"" + stream.close() + files["f"].close() + + def test_create_environ(): env = create_environ("/foo?bar=baz", "http://example.org/") expected = { @@ -409,7 +426,7 @@ def test_file_closing(): class SpecialInput: def read(self, size): - return "" + return b"" def close(self): closed.append(self)