• Post Reply Bookmark Topic Watch Topic
  • New Topic

URLDecoder problem  RSS feed

 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use JavaScript escape function for encoding arbitrary string which should be used in URL forming. Then I call URLDecoder.decode in servlet. It works fine for strings with latin character. However if I use Russian, escape string looks like that:
%u0410%u043D%u0434%u0440%u0435%u0439%20%u0420%u044B%u043B%u0438%u043D%20%20%2C%20%20%28%29
and when decode function called it thrown an exception:

I checked JavaDoc for URLDecoder and it seems can recognize only form "%xy". So where is a problem, in JavaScript escape or in URLDecoder? If it's a problem of URLDecoder is it reasonable to file a bug with Sun? What other implementation can be used as a work around?
[ October 22, 2005: Message edited by: dema rogatkin ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JS escape function is defined to encode in ISO-Latin-1. I'm not sure if you can encode Russian characters with that. Have you tried using the two-argument variant of URLDecoder.decode, and specified ISO-Latin-1 as the encoding? I'm not sure if that would be its exact name in Java, though.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I solved problem removing JavaScript escape() function. It seems there is no a standard yet how to encode Unicode in URL, RFC 1738 doesn't answer. So probably JavaScript introduces some specification not supported widely yet, however IE and FF behave consistently.

Edit: After a bit digging I found that not only me have the problem:
http://weblogs.mozillazine.org/gerv/archives/2004/05/url_encoding_co.html
[ October 22, 2005: Message edited by: dema rogatkin ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!