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-projects-issues opened this issue Nov 2, 2018 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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-projects-issues
Copy link
Collaborator Author

Dimitrios Liapis commented

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

Is the OP's statement valid?

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

Dimitrios Liapis commented

Arjen Poutsma many thanks for the opportunity.

I've raised a PR: #2010

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.1.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants