Skip to content

mime: ParseMediaType drops value with trailing semicolon #46323

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

Closed
Illirgway opened this issue May 22, 2021 · 2 comments
Closed

mime: ParseMediaType drops value with trailing semicolon #46323

Illirgway opened this issue May 22, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Illirgway
Copy link
Contributor

Illirgway commented May 22, 2021

What version of Go are you using (go version)?

// up to go current playground version
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.Version())
}

go1.16.4

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go playground env

What did you do?

https://play.golang.org/p/kIcw1CfXcUq

package main

import (
	"fmt"
	"mime"
)

func main() {
	// example from rfc2231 (p.3)

	const (
		contentTypeSucc = `message/external-body; access-type=URL;
         URL*0="ftp://";
         URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"`
		contentTypeFail = `message/external-body; access-type=URL;
         URL*0="ftp://";
         URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar";`	// <-- !!!
	)
	
	r1, p1, err1 := mime.ParseMediaType(contentTypeSucc)
	r2, p2, err2 := mime.ParseMediaType(contentTypeFail)
	
	fmt.Println(r1, p1, err1)
	fmt.Println(r2, p2, err2)
}

What did you expect to see?

message/external-body map[access-type:URL url:ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar] <nil>
message/external-body map[access-type:URL url:ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar] <nil>

What did you see instead?

message/external-body map[access-type:URL url:ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar] <nil>
message/external-body map[access-type:URL] <nil>

Analysis

this https://github.com/golang/go/blob/go1.16.4/src/mime/mediatype.go#L170 (https://golang.org/src/mime/mediatype.go?#L170) should be break instead of return

Question

Should I next time push fix commit instead of writing issue if I found both a bug and a fix to it at once?

@seankhliao seankhliao changed the title mime.ParseMediaType issue for rare case of "good"-malformed media-type value (with proposed fix) mime: ParseMediaType drops value with trailing semicolon May 22, 2021
@ianlancetaylor
Copy link
Member

If you are sure that it is a bug, it's OK to send a patch instead of filing an issue. See https://golang.org/doc/contribute.html. Thanks.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label May 22, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone May 22, 2021
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 22, 2021
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label May 22, 2021
Illirgway added a commit to Illirgway/go that referenced this issue Jul 2, 2021
Illirgway added a commit to Illirgway/go that referenced this issue Jul 2, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/332509 mentions this issue: mime: fix ParseMediaType drops value with trailing semicolon #46323

@golang golang locked and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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.

3 participants