Closed Bug 116321 Opened 18 years ago Closed 18 years ago
File extension overrides DOCTYPE
XML Parsing Error: syntax error is returned if the file extension is "XHTML" even if the DOCTYPE is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> Mozilla 0.9.5 Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.5) Gecko/20011213 The sample content validates at http://validator.w3.org/check Internet Explorer 6.0.2600 renders the content even if the file has an xhtml extension. This does not mean it's the right thing to do! Sample content: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Some title</title> </head> <body> <p>Some HTML</p> </body> </html>
The server is probably picking up on the file extension and serving the document with a MIME-type of application/xhtml+xml or text/xml. Actual MIME headers override HTTP headers specified in the document. Do you have a testcase of this online? DOCTYPE sniffing only applies for documents within the text/html MIME-type.
Sorry, I should have mentioned that in this case I was opening the file directly from the file system by dragging it from Windows Explorer onto the render area of Mozilla.
I have explicitly set the content type to HTML when adding this attachment
This has been submitted with auto-detect for the content-type
Both of the test attachments work fine as the content type has been explicitly noted by BugZilla. I'm not sure about what other tests I can perform as I don't have control over a public web server for you to link to.
Have just tried this on IIS 5. The MIME type is listed as application/xhtml+xml as you would expect. When connecting to the webserver I got the "What application should I use?" dialog box. This didn't happen when I loaded the same file from the file system (I connected to the file system of the remote machine to test remoting issues). I've opened up my IIS Server for you to have a look (these are the same file): http://myforest.dns2go.com/Extension.xhtml and http://myforest.dns2go.com/Extension.html Oh well, guess I'll re-build it in the morning!
OK, here's what I assume is happening. The file on your local system has a .xhtml extension. When Mozilla sees the file extension, it assumes the document will be XHTML, *and treats it as if it were XML, not HTML*, because not all XHTML can be classified as text/html. (Appendix C of XHTML 1.0). So by the time the parser gets to the DOCTYPE, the document is already loaded as XML, and it throws an XML error. DOCTYPE sniffing is an institution peculiar to text/html or files identified as such (.html, .htm). (And your webserver is now serving the .xhtml file as application/octet-stream, FWIW).
And the browser won't start if I rename mozilla.exe into mozilla.txt -- XHTML is an XML markup. We treat .xhtml as such from a filesystem. Your file is clearly not XHTML. Why name it with that extension in the first place? If you drop that file onto any recent server, it will serve it with an XML mimetype. Isn't it safe for us to assume that it is XML as well?
>>Why name it with that extension in the first place<< It was an accident. I can understand what you're saying and am happy to go with that approach. I don't have enough familiarity with XHTML yet to know any better. As the file system doesn't indicate the MIME type, it's neccessary to make some assumptions and what you've detailed makes sense. Thanks for your help.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.