Title
Care while building websites linking to special characters in case of Internet Explorer
Body

The other day when we were building website software to our japanese client, we had a feature where user uploads images/files and they could be downloaded / displayed in the respective pages.

Everything was fine until we realised that the client files were actually in japanese text. We still didnot have any problem in Chrome or Firefox, but when it came to Internet Explorer for some reason it tried to print the filename in japanese and for the same reason the link started displaying unwanted characters and boxes...

After digging into depth of the problem we realized that IE by default was not converting the linke from Japanese text to URL format i..e %20. hence forth we had to explicit convert the code.
 

The below code snippet is what we changed. Hope it helps others.

EARLIER CODE:

 

<a href="<%= product.product_image.url) %> ">SOME FILE NAME</a>

CHANGED TO :
 

<a href="<%= URI.escape(product.product_image.url) %>" >SOME FILE NAME</a>

What did we do... We used the RUBY's basic URI class and did an escape on the path name. so what happend was the japanese text file finally displayed as below

23%20%E7%AC%AC%EF%BC%93%E5%9B%9E%E3%80%80Part%20%EF%BC%91.jpg


This is an important change that is really necessary for 2 bit unicode characters like japanese and chinese.

Tags
Associated Tags
ruby , rails 3, unicode, japanese, conversion.
Created By
admin
Created At
2011-05-04 10:48:26 UTC
Last Updated At
2011-05-05 07:05:42 UTC
   
Comment Text
Thanks, it solved a day's work for me
Name
Amit Kumar
   
Comment Text
Yeah, it solved my problem as well...Japanese characters seem to be a big problem
Name
Derek thomas
Add Comment