-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Could not parse MediaType #6663
Comments
From what I can tell, that A space seems to be allowed between the One other thing: the class Javadoc for
So trying to directly parse the value of a |
Digging around a little more, it looks like according to RFC 822, whitespace should be allowed around the |
Indeed, according to RFC 2045, that content type is illegal, but when I tried to parse it using the corresponding API of the Spring web framework, it also worked properly org.springframework.http.MediaType mediaType = org.springframework.http.MediaType.valueOf("multipart/form-data;charset=UTF-8;boundary =--jelsaflflksafjel");
System.out.println(mediaType.getCharset());
System.out.println(mediaType);
mediaType = org.springframework.http.MediaType.valueOf("multipart/form-data; charset = UTF-8;boundary =--jelsaflflksafjel");
System.out.println(mediaType.getCharset());
System.out.println(mediaType); Console Output
So I believe that if we can handle this defect, it will be more robust |
As I mentioned in my second comment, I think my initial read was wrong and it actually is legal according to RFC 2045. I'm thinking it should be fine to allow whitespace before and after any of the separators, |
Yes, it is. |
…either side of the `=` separator in a parameter (`attribute=value`) as well as on either side of the `/` between the type and subtype (because nothing in the specification suggests that it be treated differently than the `;` or the `=`). [RFC 822](https://datatracker.ietf.org/doc/html/rfc822), which specifies the notation used to describe the syntax of a media type in [RFC 2045](https://datatracker.ietf.org/doc/html/rfc2045#section-5.1), seems to [indicate](https://datatracker.ietf.org/doc/html/rfc822#section-3.1.4) that spaces should be allowed here (and in fact if it didn't, nothing in the specification would allow them around the `;` either). Fixes #6663. RELNOTES=`net`: Made `MediaType.parse` allow and skip over whitespace around the `/` and `=` separator tokens in addition to the `;` separator for which it was already being allowed. PiperOrigin-RevId: 553222041
When GuavaAPI parse Content-Type String to GuavaMediaType, there exception happen:
Maven Dependency:
Code:
Exception:
When I delete the space charactor between 'boundary' and '=---' like this;
Then It's worked!
By the way, This Content-Type: 'multipart/form-data;charset=UTF-8;boundary =--jelsaflflksafjel' with space charactor was generated by trip framework
The text was updated successfully, but these errors were encountered: