-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: mime: handling duplicate media parameters #28618
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
Comments
It would help if you could point to packages that generate this invalid information, and if you could point to how other MIME parsing code, in other languages, handles this case. That is, we want to accept data that is out there in the wild, but we want to avoid being unnecessarily loose. Thanks. |
@ianlancetaylor I have found the following examples on Python, Java and C#. All of them returns charset as "UTF-8" correctly, none throws an error. Example in Python 3:
Example in Java:
prints "UTF-8" Example in C#:
prints "text/plain (UTF-8)" |
The example in Go:
prints "mediaType = '', params = map[], err = mime: duplicate parameter name" |
Thanks, that wasn't quite what I was asking. Can you describe which programs generate the duplicate information? I'm trying to understand why we should make this change. If no program generates duplicates, then it seems to me that stricter is better, as it avoids any confusion about which parameter applies. |
@neganovalexey you wrote "It is possible to receive an email ...". The important question is "is it likely?" Do you have instances of this happening in real use cases? If not, then we are unlikely to add what might end up being some kind of security hole (by picking one or the other differently from other software) for purely speculative motivations. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
I actually have such an email in my Inbox. The header field is this:
|
It is possible to receive an email that does not follow the specification, i. e. an email with the Content-Type header like
Golang standard library does not allow duplicate media parameters so it is impossible to parse such a header. But two instances of the 'charset' parameter have the same value here, so it can be determined unambiguously.
I suggest making the mime.ParseMediaType function more tolerant to such errors. It should not stop the execution if it detected duplicate parameters have the same value. In order not to change behavior of any existing Go program, some special error value may be returned along with parsed media type and parameters.
The text was updated successfully, but these errors were encountered: