While investigating an issue for one of our users, we came across this quirk of IE8* which causes URL encoded links to be malformed when they are used for relative links on a local web page. We decided to document this here for information.
*It appears that IE7 may also exhibit this problem. IE6 does not, however.
As you may or may not know, certain characters in a URL need to be "URL encoded" (aka "Percent encoding") for the URL to be valid and free of ambiguity. This includes the ampersand (&) character which is encoded as "%26".
Browsers and web servers should be aware of URL encoding and correctly decode these characters to determine the filenames and paths as necessary. In most cases, they do.
In the following scenario however, IE8 fails to do so.
When a page is hosted locally (on your computer), and accessed via a URL such as the following:
file:///c|/myfiles/search.html
This page may contain a relative link to a file named "bill&ted.pdf" in the same folder in the form of:
<a href="./bill%20%26%20ted.pdf">my file</a>
This would be valid because it is expecting to construct a URL. And indeed, it is correct when you hover the mouse over the link or right click and select "Copy shortcut". The constructed URL is:
file:///c|/myfiles/bill%20%26%20ted.pdf
However, while this works fine in Firefox 3, Google Chrome, and IE6 or earlier, it fails in IE8. IE8 attempts to translate this to a local file path but fails to decode the ampersand character in the process, such that it looks for a file named so:
C:\myfiles\bill %26 ted.pdf
Because of the failure to decode the ampersand character, the filename is incorrect and it becomes a broken link.
At this point, we believe this is a bug in IE8 and can not find any information to indicate otherwise.
The exact same set of files will work perfectly fine in IE8 when it is hosted over the network and accessed via UNC paths (e.g. \\machinename\myfiles\search.html) or when hosted online and accessed via a HTTP URL.
*It appears that IE7 may also exhibit this problem. IE6 does not, however.
As you may or may not know, certain characters in a URL need to be "URL encoded" (aka "Percent encoding") for the URL to be valid and free of ambiguity. This includes the ampersand (&) character which is encoded as "%26".
Browsers and web servers should be aware of URL encoding and correctly decode these characters to determine the filenames and paths as necessary. In most cases, they do.
In the following scenario however, IE8 fails to do so.
When a page is hosted locally (on your computer), and accessed via a URL such as the following:
file:///c|/myfiles/search.html
This page may contain a relative link to a file named "bill&ted.pdf" in the same folder in the form of:
<a href="./bill%20%26%20ted.pdf">my file</a>
This would be valid because it is expecting to construct a URL. And indeed, it is correct when you hover the mouse over the link or right click and select "Copy shortcut". The constructed URL is:
file:///c|/myfiles/bill%20%26%20ted.pdf
However, while this works fine in Firefox 3, Google Chrome, and IE6 or earlier, it fails in IE8. IE8 attempts to translate this to a local file path but fails to decode the ampersand character in the process, such that it looks for a file named so:
C:\myfiles\bill %26 ted.pdf
Because of the failure to decode the ampersand character, the filename is incorrect and it becomes a broken link.
At this point, we believe this is a bug in IE8 and can not find any information to indicate otherwise.
The exact same set of files will work perfectly fine in IE8 when it is hosted over the network and accessed via UNC paths (e.g. \\machinename\myfiles\search.html) or when hosted online and accessed via a HTTP URL.