5

This is not a new queestion

There are quite a few of questions here on SO about IE having some problems with handling special characters in the querystrings. In all of the cases it is the same: Chrome, Firefox, Safari (everyone) handles the UTF-8 encoded URLs correctly, almost all of them even handles the cases where the IRIs aren't encoded into URLs. But IE insists on make life hard for the developers.

As I have run into the problem myself, and have worked quite a bit with it. To me it seems that IE for some reason insists on decoding the UTF-8 encoded URL into ISO-8859-1 before sending it to the server.

My case

I am a resident in Denmark, and therefor I have to work with the danish letters æøå. There a many cases where I want to send parameters from my views into some C# methods. Two examples of such places where the special characters often pop up:

  1. Searching
  2. Specification of filename for a downloaded files

Say a Dane wants to search for the danish word "æblegrød" (special kind of apple pie). In Chrome and Firefox, if I just feed the browser with the IRI:

http://example.com/Search/QuickSearch?searchQuery=æblegrød

The query sent to the server would look like this:

http://example.com/Search/QuickSearch?searchQuery=%C3%A6blegr%C3%B8d

In Internet Explorer however it would look like this:

http://example.com/Search/QuickSearch?searchQuery=æblegrød

It is now easy to see what the problem is. Firefox & Chrome are URL encoding the URLs

... each byte that is not an ASCII letter or digit to %HH, where HH is the hexadecimal value of the byte

http://www.w3.org/International/O-URL-code.html

Where Internet Exlorer instead is doing a direct UTF-8 encoding of the string, resulting in "æblegrød". This is also the same end results as if you take a UTF-8 string and decode it as if it was ISO-8859-1, is this a coincidence?

I have tried some things

As Internet Explorer has the option to "send URL path as UTF-8" I tried disabling that. Changing nothing.

As it went wrong when IE has to handle "searchQuery=æblegrød" I tried encoding the IRI before handing it to the browser. Resulting in all browsers getting the following URL to work with:

http://example.com/Search/QuickSearch?searchQuery=%C3%A6blegr%C3%B8d

IE however doesn't care, what I see in the networking log is still the URL

http://example.com/Search/QuickSearch?searchQuery=æblegrød

being sent to the server.

This is how my configuration is:

  1. Files are saved as UTF-8
  2. I set the meta tag:

    <meta charset="UTF-8">
    
  3. IE sends URL-paths as UTF-8 (also set IE to do this for intranet querystrings)

  4. Globalization set to UTF-8

    <globalization          
        uiCulture="da-DK"
        culture="da-Dk"
    
        fileEncoding="utf-8"
        responseEncoding="utf-8"
        requestEncoding="utf-8"
        responseHeaderEncoding="utf-8" />
    

I am running out of ideas, I don't know what it is that I am doing wrong. I am leaning towards IE creating the havoc, but I genuinely do not know if it is something that I have set up wrongly in my project.

5
  • What you are encountering is a known problem with many versions of IE, including 11. See Unicode in URL changes for IE11 and encoding of query string parameters in IE10, for instance. Oct 29, 2015 at 2:07
  • 1
    æblegrød is the UTF-8 encoded form of æblegrød when viewed as ISO-8859-1. IE is encoding the querystring to UTF-8 correctly, it is just transmitting the UTF-8 as-is (most likely because your HTML page's charset is UTF-8) instead of hex-encoding the non-ASCII byte octets in %HH format, like other browsers do. Oct 29, 2015 at 2:09
  • 2
    This issue might be related to how IE submits HTML forms, as described in this MSDN blog article: Brain Dump: International Text. Note: "URLs in IE may use up to three (!!) different encodings at once: punycode in the hostname, %-escaped UTF-8 for the path, and raw codepaged-ANSI for the query and fragment components. This is clearly a mess, but fixing it to match the IRI specification incurs compatibility costs. (Trust me, we’ve tried!)". Oct 29, 2015 at 2:12
  • Basically, there is nothing you can really do to change IE's behavior. This is just how it works. You are not doing anything wrong on your end. Oct 29, 2015 at 2:17
  • @RemyLebeau if there is nothing I can do to change IE's behavior, is there then something I can do to work either around or with it? As I can understand, EricLaw says that I should be able to work with "properly encoded" URLs, but trying that, I get what you also said "æblegrød is the UTF-8 encoded form of æblegrød when viewed as ISO-8859-1" (also mention in the "I have tried some things" section)
    – Squazz
    Oct 29, 2015 at 7:50

1 Answer 1

7

An answer to the future people hitting this question.

Playing around with this, I got to the conclusion that the only thing I could do was to encode all of my URL's, and then work with the Content Disposition (with help from this SO post) to make it work for different browsers. The solution is not perfect, it still has some flaws, but it is the best approach I have found so far.

In all of my cases, the links were build with JS, so encodeURIComponent is my go-to method to encode the URLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.