[whatwg] Charset sniffing from XML prolog

Kartikaya Gupta lists.whatwg at stakface.com
Wed Oct 7 16:51:03 PDT 2009


On Wed, 07 Oct 2009 19:34:18 -0400, Boris Zbarsky <bzbarsky at MIT.EDU> wrote:
> On 10/7/09 7:12 PM, Kartikaya Gupta wrote:
> > If a document is served as text/html, but contains an XML prolog with an encoding attribute, it seems that all Firefox, Opera, and Chrome all pick up the encoding from the prolog and use it when parsing the rest of the document. (IE6 does not). The HTML5 spec doesn't seem to include XML-prolog checking in its encoding sniffing algorithm, should it?
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <html>insert utf-8 content here, or alert(document.inputEncoding) for browsers that support it</html>
> 
> data:text/html,<?xml version="1.0" 
> encoding="utf-8"?><html><script>alert(document.inputEncoding)</script></html>
> 
> Shows ISO-8859-1 for me in Firefox over here.
> 

Strange. I got "UTF-8" when I pasted that into the address bar. For reference, the version of FF I'm using is:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3

I tried it again in Chrome and if I paste the above in the address bar I get US-ASCII. But if I save it to a file and then load it I get UTF-8. I checked the headers being sent from Apache and they don't include any sneaky encoding hints, just Content-Type: text/html.

kats


More information about the whatwg mailing list