[whatwg] An alternative approach to section 9 of Mime Sniffing

I propose rewriting section 9 and parts of section 10 in a different way, to use the ABNF format in RFC 5234. (Note that ABNFs are already  used in the current Fetch specification.) With this approach, the definitions for "byte pattern",  "pattern mask", and the "pattern matching algorithm" can be eliminated (all of which are found before section 9.1).

An example for the image pattern matching algorithm is given below.
 
---------------------------------------------------

9.1  Matching an image type pattern

The image pattern matching algorithm takes a byte sequence as input.  The algorithm goes through the following image types in the order given.  For each image MIME type given below, if the start of the byte sequence matches its ABNF, return the concatenation of "image/" and the name of the ABNF (in lowercase), and terminate the image pattern matching algorithm. 

vnd.microsoft.icon = %x00.00.01.00 
   ; A Windows Icon signature. 
bmp = %x42.4D 
   ; The string "BM", a BMP signature. 
gif = %x47.49.46.38 (%x37 / %x39) %x61 
   ; The string "GIF87a" or "GIF89a", a GIF signature. 
webp = %x52.49.46.46 4OCTET %57.45.42.50.56.50
   ; The string "RIFF" followed by four bytes followed by the string "WEBPVP". 
png = %x89.50.4E.47.0D.0A.1A.0A
   ; The byte 0x89 followed by the string "PNG"
   ; followed by CR LF SUB LF, the PNG signature. 
jpeg = %xFF.D8.FF
   ;     The JPEG Start of Image marker followed by the indicator 
   ; byte of another marker. 

If the start of the byte sequence doesn't match any ABNF given above, return undefined.

---------------------------------------------------

I would appreciate comments.

--Peter

Received on Thursday, 23 May 2013 06:11:19 UTC