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

Multipart fix #2126

Merged
merged 1 commit into from May 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -12,6 +12,8 @@ Unreleased
- Fix some types that weren't available in Python 3.6.0. :issue:`2123`
- ``cached_property`` is generic over its return type, properties
decorated with it report the correct type. :issue:`2113`
- Fix multipart parsing bug when boundary contains special regex
characters. :issue:`2125`


Version 2.0.0
Expand Down
4 changes: 2 additions & 2 deletions src/werkzeug/sansio/multipart.py
Expand Up @@ -101,7 +101,7 @@ def __init__(
# group to understand if it is an epilogue boundary.
self.preamble_re = re.compile(
br"%s?--%s(--[^\S\n\r]*%s?|[^\S\n\r]*%s)"
% (LINE_BREAK, boundary, LINE_BREAK, LINE_BREAK),
% (LINE_BREAK, re.escape(boundary), LINE_BREAK, LINE_BREAK),
re.MULTILINE,
)
# A boundary must include a line break prefix and suffix, and
Expand All @@ -110,7 +110,7 @@ def __init__(
# understand if it is an epilogue boundary.
self.boundary_re = re.compile(
br"%s--%s(--[^\S\n\r]*%s?|[^\S\n\r]*%s)"
% (LINE_BREAK, boundary, LINE_BREAK, LINE_BREAK),
% (LINE_BREAK, re.escape(boundary), LINE_BREAK, LINE_BREAK),
re.MULTILINE,
)

Expand Down
8 changes: 4 additions & 4 deletions tests/sansio/test_multipart.py
Expand Up @@ -10,18 +10,18 @@


def test_decoder_simple() -> None:
boundary = b"---------------------------9704338192090380615194531385"
boundary = b"---------------------------9704338192090380615194531385$"
decoder = MultipartDecoder(boundary)
data = """
-----------------------------9704338192090380615194531385
-----------------------------9704338192090380615194531385$
Content-Disposition: form-data; name="fname"

ß∑œß∂ƒå∂
-----------------------------9704338192090380615194531385
-----------------------------9704338192090380615194531385$
Content-Disposition: form-data; name="lname"; filename="bob"

asdasd
-----------------------------9704338192090380615194531385--
-----------------------------9704338192090380615194531385$--
""".replace(
"\n", "\r\n"
).encode(
Expand Down