Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer having problems with special chars in querystrings

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.

like image 755
Squazz Avatar asked Oct 28 '15 12:10

Squazz


People also ask

What special characters are not allowed in URL?

These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

What is special character not allowed?

Special characters, including the following are not acceptable: (){}[]|`¬¦! "£$%^&*"<>:;#~_-+=,@. If you do use a disallowed character and the system does not recognize your mistake you will not be allowed to use the password or username to log into your account later.


1 Answers

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.

like image 62
Squazz Avatar answered Oct 07 '22 21:10

Squazz