Skip to content

mime: FormatMediaType should quote control characters #7668

@rui314

Description

@rui314
What does 'go version' print?
go version devel +1afdecdd77c1 Sat Mar 29 17:10:25 2014 -0400 linux/amd64

What steps reproduce the problem?
http://play.golang.org/p/LcQhZpJkX2

1. Call mime.FormatMediaType with parameters containing an ASCII control character
2. See the return value

What happened?
It returns a formatted string containing a control character as is.

What should have happened instead?
It should quote a control character with \ or return the empty string. Here is the
definition of quoted-string (http://www.ietf.org/rfc/rfc2616.txt). A control character
can appear as quoted-pair but not as qdtext.

       quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
       quoted-pair    = "\" CHAR
       CHAR           = <any US-ASCII character (octets 0 - 127)>
       qdtext         = <any TEXT except <">>
       TEXT           = <any OCTET except CTLs,
                        but including LWS>
       CTL            = <any US-ASCII control character
                        (octets 0 - 31) and DEL (127)>

(It's actually surprising to me that it allows even a NUL after a backslash, but it's
what the standard says. It may be a spec bug?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions