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: FormatMediaType doesn't allow to create Content-Disposition #9624

Closed
rasky opened this issue Jan 17, 2015 · 11 comments
Closed

mime: FormatMediaType doesn't allow to create Content-Disposition #9624

rasky opened this issue Jan 17, 2015 · 11 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rasky
Copy link
Member

rasky commented Jan 17, 2015

On Go 1.4 (darwin), mime.FormatMediaType checks whether the first argument (aptly called mediatype) contains a forward slash, and returns an empty string if it doesn't. This doesn't allow to use this function to format a Content-Disposition header, because the values for such header are not proper media types (they are usually inline or attachment). Notice that the documentation of the reverse function mime.ParseMediaType explicitly says that it can be used to parse Content-Disposition headers, so it looks like this limitation should be lifted.

@bradfitz
Copy link
Contributor

Yeah, looks like we're inconsistent here. Content-Dispositions are different, but we've supported them in ParseMediaType forever (my fault, I guess), despite them not being media types technically. So I guess we could be looser in FormatMediaType for symmetry.

@bradfitz bradfitz added this to the Go1.5 milestone Jan 17, 2015
@mikioh mikioh changed the title mime.FormatMediaType doesn't allow to create Content-Disposition mime: FormatMediaType doesn't allow to create Content-Disposition Jan 17, 2015
@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Too late for Go 1.5.

@rsc rsc modified the milestones: Unplanned, Go1.5 Jun 29, 2015
@odeke-em
Copy link
Member

If you wouldn't mind @rasky, could you provide me with some failing test samples or just values that should be accepted yet are failing? Thanks.

@zensh
Copy link

zensh commented Mar 1, 2017

@odeke-em

fmt.Println(mime.ParseMediaType(`attachment; filename="????.png"; filename*=UTF-8''%E6%95%B0%E6%8D%AE%E7%BB%9F%E8%AE%A1.png`))
fmt.Println(mime.FormatMediaType("attachment", map[string]string{"filename": "数据统计.png"}))
fmt.Println(mime.FormatMediaType("attachment", map[string]string{"filename": "test.png"}))

@andrius4669
Copy link
Contributor

Seems to be working with current Go (go1.11).

@bradfitz
Copy link
Contributor

@andrius4669, does it? https://play.golang.org/p/ndwGaJDMBO4

I see:

attachment map[filename:数据统计.png] <nil>

attachment; filename=test.png

@zensh, do you expect the middle case to work? I guess it should encode it with UTF-8 the same way as the first line parses?

@bradfitz bradfitz added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 20, 2018
@andrius4669
Copy link
Contributor

@bradfitz sorry, I didn't meant samples specified by zensh.
Initial issue about FormatMediaType and ParseMediaType not being symmetric about both allowing disposition has been fixed apparently, it now allows that.
It currently cannot encode non-ASCII unicode chatacters because it doesn't implement encoding specified in RFC 2231 section 4, and instead intentionally fail if it detects such input.
#28849 was somewhat related to this (and I was told to fill separate feature request about RFC2231 encoding).
I guess this issue could be used for discussion about that encoding, if you think this is right.

@andrius4669
Copy link
Contributor

Sorta working on this now.

@gopherbot
Copy link

Change https://golang.org/cl/154760 mentions this issue: mime: encode CTL and non-US-ASCII characters in FormatMediaType

@andrius4669
Copy link
Contributor

#29328

@zensh
Copy link

zensh commented May 24, 2019

@andrius4669 👍

@golang golang locked and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants