Skip to content

mime: ParseMediaType drops value with trailing semicolon #46323

@Illirgway

Description

@Illirgway

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions