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

MediaType.parseMediaTypes fails if the input contains a comma [SPR-17459] #21991

Closed
spring-issuemaster opened this Issue Nov 2, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Nov 2, 2018

Fabian Kürten opened SPR-17459 and commented

For the class org.springframework.http.MediaType

Parsing a list of media types fails if a media type contains a comma ",".
For example this fails with InvalidMediaTypeException:

MediaType.parseMediaTypes("foo/bar;param=\",\"");

While the comma is the separator for different media types in a header my understanding is that it is legal to use tspecial characters (like comma) inside a quoted string.
However the implementation of parseMediaTypes tokenizes blindly by comma, ignoring quotes. The resulting parts are invalid media types (ends with an open quote) which leads to the exception.
 


Affects: 5.0.4, 5.1.2

Referenced from: commits f4b05dc, 7bbd4c6, ba3fef3

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 4, 2018

Dimitrios Liapis commented

I could pick this up if no-one has done so already.

Is the OP's statement valid?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 6, 2018

Arjen Poutsma commented

I could pick this up if no-one has done so already.

Great!

Is the OP's statement valid?

It is. We currently do a simple comma-based tokenisation, see

String[] tokens = StringUtils.tokenizeToStringArray(mediaTypes, ",");

Instead, we should check whether the comma is quoted, like we do when parsing a single media type:

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 6, 2018

Dimitrios Liapis commented

Arjen Poutsma many thanks for the opportunity.

I've raised a PR: #2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.