[whatwg] [mimesniff] Review request: Parsing a MIME type

Gordon P. Hemsley gphemsley at gmail.com
Sat Jun 1 08:41:34 PDT 2013


On Fri, May 31, 2013 at 11:50 PM, Peter Occil <poccil14 at gmail.com> wrote:
>
>> * Another important point to notice is the fact that this algorithm
>> allows parameter names to appear without values. This is useful in
>> situations such as the "base64" option in data: URLs that use the mere
>> presence or absence of a parameter to set its boolean value.
>
>
> Since you mention data URLs I should note that data URLs can be percent
> encoded, which HTTP
> and MIME headers can't be. This raises additional considerations when
> parsing a data URL's MIME type correctly;
> see reference [1] for test cases.  In particular:
>
> [1]: http://greenbytes.de/tech/tc/datauri/

This is a very useful resource; thank you for pointing it out to me.

Realize now that that's the only thing that matters: What do the browsers do?

(And percent encoding doesn't matter, as that gets handled before the
parsing begins.)

> * A data URL that begins with "data:," or "data:;base64," (with no MIME
> type) is assumed to have the MIME type
>  "text/plain;charset=us-ascii" under RFC2397.
> * A data URL that begins with  "data:;" (with no type or subtype, but with
> parameters) is assumed to have the MIME type
>  "text/plain" under RFC2397.

An empty or invalide MIME type will get treated as unknown and will
eventually be sniffed (if it isn't already). I'll have to consider
what to do with the base64 and other parameters parts, though.

> * The word "base64" can only appear at the end of the MIME type, so that a
> data URL like
>   "data:application/example;base64;foo=bar,AA==" will not be encoded in
> base64, strictly speaking. A parameter name (base64 or otherwise)
>   cannot otherwise appear without a parameter value.

As I mentioned, "strictly speaking" doesn't matter, as all browsers do
the same thing, according to the resource you linked: base64
parameters with values are fine; base64 boolean parameters in other
than last place are warnings. (Not sure what the reasoning behind that
distinction is, but that's what reality is.)

So it seems the only issue I have to worry about is what to do with
MIME types which only have parameters.

Regards,
Gordon

--
Gordon P. Hemsley
me at gphemsley.org
http://gphemsley.org/http://gphemsley.org/blog/


More information about the whatwg mailing list