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

mime: handling invalid mime media parameters #19498

Closed
neganovalexey opened this issue Mar 10, 2017 · 5 comments
Closed

mime: handling invalid mime media parameters #19498

neganovalexey opened this issue Mar 10, 2017 · 5 comments

Comments

@neganovalexey
Copy link
Contributor

neganovalexey commented Mar 10, 2017

Sometimes it's necessary to deal with emails that do not follow the specification; in particular, it's possible to download such email via gmail.
When Golang standard library handle invalid mime media parameters, it returns nils and error, although there is a valid media type, which may be returned. If this behavior changes, it may not affect any existing programs, but it will help to parse some emails.

I suggest to change file src/mime/mediatype.go as follows:

diff --git a/mediatype.go b/mediatype.go
index 4383431..758d621 100644
--- a/mediatype.go
+++ b/mediatype.go
@@ -94,6 +94,9 @@ func checkMediaTypeDisposition(s string) error {
    return nil
 }
 
+// ErrInvalidMediaParameter means that mime media parameter list is invalid
+var ErrInvalidMediaParameter = errors.New("mime: invalid media parameter")
+
 // ParseMediaType parses a media type value and any optional
 // parameters, per RFC 1521.  Media types are the values in
 // Content-Type and Content-Disposition headers (RFC 2183).
@@ -134,7 +137,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e
                return
            }
            // Parse error.
-           return "", nil, errors.New("mime: invalid media parameter")
+           return mediatype, nil, ErrInvalidMediaParameter
        }
 
        pmap := params
@@ -368,4 +371,3 @@ func unhex(c byte) byte {
    }
    return 0
 }
-
-- 
2.7.4
@ALTree
Copy link
Member

ALTree commented Mar 10, 2017

Can you edit your message so that it includes the proposed API change (instead of putting the change in an attachment)?

@ALTree ALTree changed the title proposal: handling invalid mime media parameters proposal: mime: handling invalid mime media parameters Mar 10, 2017
@neganovalexey
Copy link
Contributor Author

OK

@ALTree ALTree added this to the Proposal milestone Mar 11, 2017
@rsc
Copy link
Contributor

rsc commented Mar 13, 2017

@bradfitz says yes. We will need to document the new behavior; unclear we need the new error variable. I'd leave that out.

@rsc rsc changed the title proposal: mime: handling invalid mime media parameters mime: handling invalid mime media parameters Mar 13, 2017
@rsc
Copy link
Contributor

rsc commented Mar 13, 2017

CL welcome.

@rsc rsc modified the milestones: Go1.9, Proposal Mar 13, 2017
@gopherbot
Copy link

CL https://golang.org/cl/38190 mentions this issue.

@golang golang locked and limited conversation to collaborators Mar 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants