0

hen Escape function was used in JavaScript to encode a string (with accents) which encoding format should be used to decode on server side?

Input string : Aéroport
After javascript encoding: A%E9roport
After decoding on server side without using any encoding: A�roport
Decoding using UTF7 or Default: Aéroport

While Decoding: UTF7 and Default encoding gives correct result in dev environment.

Some results from Immediate window with initial string as Bér:

HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.GetEncoding("iso-8859-8")) : "Bיr"<br/>
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.UTF7) : "Bér"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.Default) : "Bér"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.ASCII) : "B?r"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.BigEndianUnicode): "䋩�"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.UTF32) : "�"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.UTF8) : "B�r"
HttpUtility.UrlDecode(searchTerm, System.Text.Encoding.GetEncoding("ISO-8859-8")) : "Bיr"

Will Encoding.Default be reliable? Or will UTF7 work in every case?
Is input string decoded as per client's settings?

user1155631
  • 1
  • 1
  • 1
  • I would prefer UTF8 when possible. For me, javascript `encodeURI('Aéroport')` gives `"A%C3%A9roport"` and `HttpUtility.UrlDecode("A%C3%A9roport", System.Text.Encoding.UTF8)` gives `Aéroport` – Kunukn May 07 '14 at 08:27
  • Thanks for the input. I tried all available encoding but none seems to work for me apart from UTF7 and Default. – user1155631 May 07 '14 at 11:21
  • I would find out why your javascript encoding gives A%E9roport. Is it intended? Are you encoding your javascript in UTF-7 on purpose? – Kunukn May 07 '14 at 11:27
  • Hi Kunukn, as it was a legacy application and script in there used escape instead of encodeURI. I was trying to change it in our application, in server side code. Now, finally planning to change Escape to encodeURI in all places in the script. Many thanks for your useful inputs. – user1155631 May 07 '14 at 14:01

0 Answers0