golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124k stars 17.67k forks source link

mime: ParseMedia fails to parse googleapis batch boundary #8532

Closed gopherbot closed 9 years ago

gopherbot commented 10 years ago

by sergiusens:

When using Google's batch API for GMail, the responses contain a ContentType that looks
like this:

multipart/mixed; boundary=batch_Qau-LYGqak0=_AApYZR4VvsU=

This fails to work with ParseMediaType with an error of

mime: invalid media parameter

Here's a playground example: http://play.golang.org/p/3p6UFZau34

Removing the '='s from the boundary lead to a successful parsing of the Content Type.
ianlancetaylor commented 10 years ago

Comment 1:

Labels changed: added repo-main, release-none.

bradfitz commented 10 years ago

Comment 2:

Google really sends that? That looks illegal.
RFC 2045 says:
     content := "Content-Type" ":" type "/" subtype
                *(";" parameter)
                ; Matching of media type and subtype
                ; is ALWAYS case-insensitive.
     parameter := attribute "=" value
     attribute := token
                  ; Matching of attributes
                  ; is ALWAYS case-insensitive.
     value := token / quoted-string
     token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
                 or tspecials>
     tspecials :=  "(" / ")" / "<" / ">" / "@" /
                   "," / ";" / ":" / "\" / <">
                   "/" / "[" / "]" / "?" / "="
                   ; Must be in quoted-string,
                   ; to use within parameter values
So looking at the boundary part in your example above, it's not quoted, so it's not a
quoted string, which means it must be a token.
But a token excludes tspecials, and "=" is a tspecial.
Hence, invalid.
Please demonstrate how Google sends this and I'll try to kick somebody to fix it.

Owner changed to @bradfitz.

Status changed to WaitingForReply.

gopherbot commented 10 years ago

Comment 3 by sergiusens:

Right, if google returned the boundary quoted, it would work fine:
http://play.golang.org/p/ngT5gWKjWh
Here's a short hackish example where I've included the response dump for
when I run it:
https://gist.github.com/sergiusens/7f75c3593710e1f40abc
I used this as a guide https://developers.google.com/gmail/api/guides/batch
bradfitz commented 10 years ago

Comment 4:

Thanks for the report.
I filed an internal bug.
Google employees can follow along at go/8532-to-internal

Status changed to Accepted.

bradfitz commented 10 years ago

Comment 5:

The regression has been identified internally and a fix is in review.
bradfitz commented 10 years ago

Comment 6:

The fix & tests have been submitted internally. They'll be live whenever they do their
next push.
Closing this bug, as Go's doing the right thing.
Thanks again for reporting.

Status changed to WorkingAsIntended.