All posts by Lachlan Hunt

Validating (X)HTML With IE Using File Upload

Warning: The following describes how to modify the registry in order to trick Windows XP SP2 into allowing text/html to be sent with file uploads. This hack has known side affects which may affect other applications running on your system, some of which are discussed in the comments. As a result, I accept no responsibility for damage caused to your system as a result of applying this hack, and this solution is provided as-is, with no guarentee, warranty or support. If you do not understand the regitry, nor how to reverse any change, then do not apply these changes – use them at your own risk.

Update: This technique is no longer required for HTML. Please see Validation by file upload and Internet Explorer on WinXP SP2

After downloading Windows XP Service Pack 2 recently, I was shocked that IE was now sending HTML documents with a .htm or .html extension as text/plain, thus causing any the W3C Markup Validator to issue this warning message:

Sorry, I am unable to validate this document because its content type is text/plain, which is not currently supported by this service.

The Content-Type field is sent by your web server (or web browser if you use the file upload interface) and depends on its configuration. Commonly, web servers will have a mapping of filename extensions (such as “.html”) to MIME Content-Type values (such as text/html).

That you recieved this message can mean that your server is not configured correctly, that your file does not have the correct filename extension, or that you are attempting to validate a file type that we do not support yet. In the latter case you should let us know that you need us to support that content type (please include all relevant details, including the URL to the standards document defining the content type) using the instructions on the Feedback Page.

This essentially means that it was impossible to validate any local HTML document using IE. This is really annoying, especially for any unfortunate developers who are forced to develop using only IE at work. Although I do pity anyone in that situation, there is now some relief!

After spending about half an hour searching through the registry for any setting that could be causing .html files to be sent as text/plain, I realised that it would be eaiser to find where the setting for other content types that do work, such as CSS. So, I found the setting for that, modified, and tested. When the CSS Content Type value was set to anything but text/html, IE uploaded the file with that MIME type. Thus, I came to the conclusion that it was not that the setting was incorrect, but that something in Windows security was preventing any text/html content being sent by changing it to text/plain on the way.

After that, I tried setting the valud for .html files to another type that the validator may support, such as text/sgml or application/sgml, but sadly, without luck! But, just before giving up all hope, I realised that perhaps Windows security, being as insecure as ever, is only checking for an exact match on the content type being set by IE with file uploads. I was correct!

In a normal HTTP header, the Content-Type can also include a charset parameter. For example:

Content-Type: text/html; charset=UTF-8

So, I figured, what if I want IE to send a charset parameter also. I set the Content Type value in the registry to that above, and it worked perfectly — the file validated!!! However, the charset will not always be UTF-8, or any other charset for that matter, so I removed the chaset parameter, and was left with the value text/html; That extra little semi-colon on the end is enough to bypass Windows security, and validate any HTML file.

Then, I remembered that IE also does not know how to validate XHTML documents either. So, I went to the registry key for .xhtml files, added the application/xhtml+xml MIME type, tested and Guess What! It Worked.

I have exported the required settings from the registry and they are availble here. IE6-SP2-Content-Type-text-html.reg will fix the value for text/html, and IE6-SP2-Content-Type-application-xhtml+xml.reg will add the MIME type for XHTML documents. Download them both, inspect their contents to ensure that they are safe, and apply them by launching them. You will be prompted by Windows to confirm that you want to apply the settings.

Update: For any users of ICQ: If you use change the text/html value to text/html; then each time the ICQ advertisement rotates, you may be prompted to save the file, because it is an unknown file type. I don’t konw why this happens, because IE still works the same as always — full of bugs! But for some reason it affects ICQ. I recommend you only apply that work around on computers that you do not use ICQ on, or else change it each time you need to validate with IE.

GMail GSpot

I have some GMail invites if anyone wants one. I have 5 left at the moment, but I’ll probably get more soon enough. If you want one, leave a comment or send me an email to <lachyhunt@gmail.com> with the subject “[GSpot] Invite Me.

On another note, I have decided to start an experement. I want to see how long it can take to fill up a whole Gigabyte worth of SPAM!!! The email address is <spam.my.gspot@gmail.com>. Feel free to spam it, or distribute it to anyone or any website you feel like. I’m aiming to fill it within a year — that doesn’t seem too unreasonable, I think I can manage it.

So, come on! Get involved and get in touch with my GSpot!

Car Service Means No Mac

This morning, I took my car in for a service. I thought it would just be a simple service — they’d change the oil, check the tires, clean the window, or whatever else they do for a normal service. But NO! It turns out I’ve blown the head gasket! I don’t really know what that is, but apparently it very serious, and caused oil to leak somewhere it shouldn’t have) I got a call from them letting me know how bad it was, and that it was going to cost anywhere from $800 to $1500 AUD, which is quite a bit more expensive than the $90 service I was expecting. But what else should I expect when I’m driving around in an old Hyundai Excel (1992 model). I know. They don’t really excel at anything, but that’s what they’re called.

I had been saving up for, and planning to buy my first Mac soon. I was considering getting one of those new iMacs, but now I have to continue using this old, slow and insecure Windows machine. I really wanted to get one — Macs seem to be the preferred system among web developers, and I really need access to Safari so I can develop websites to work with it.

So, I had a big decision to make. Either I risk leaving the car until I can get back to Parkes where my brother can fix it for less (It’s very handy having a mechanic in the family); or I get it done here in Sydney, even though it may cost more but is probably better for the car. Either way, getting a Mac would have to wait till I can save up again, so I figured the risk wasn’t worth it and decided to get it fixed here. Oh well, I guess I’ll just have to wait another few months before I get a Mac. Unless I get lucky and my boss decides to give a bonus for turning up to work on time. ?