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

fix for weird requests with media types with extra / #153

Merged
merged 4 commits into from
Oct 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/153.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix parsing mimetypes in Accept header with an extra slash. @djay
2 changes: 1 addition & 1 deletion src/plone/rest/negotiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def parse_accept_header(accept):
for media_range in accept.split(","):
media_type = media_range.split(";")[0].strip()
if "/" in media_type:
type_, subtype = media_type.split("/")
type_, subtype = media_type.split("/", 1)
media_types.append((type_, subtype))
return media_types

Expand Down
5 changes: 5 additions & 0 deletions src/plone/rest/tests/test_negotiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def test_parse_all_media_types_accept_header(self):
def test_parse_invalid_accept_header(self):
self.assertEqual([], parse_accept_header("invalid"))

def test_parse_mimetype_with_extra_slash(self):
self.assertEqual(
[("application", "x/y")], parse_accept_header("application/x/y")
)


class TestServiceRegistry(unittest.TestCase):
def test_register_media_type(self):
Expand Down
Loading