0

When I do:

encodeURIComponent('Cancún, Mexico');

It returns:

Canc%C3%BAn%2C%20Mexico

According to this: http://www.degraeve.com/reference/urlencoding.php

The character: ú should be %FA but instead its %C3%BA why is this and how do I fix this without having to do a lot of string replacement?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Malcr001
  • 8,179
  • 9
  • 44
  • 57

1 Answers1

0

According to this: http://www.degraeve.com/reference/urlencoding.php the character: ú should be %FA but instead its %C3%BA why is this and how do I fix this without having to do a lot of string replacement?

You should not need to fix anything at all. According to https://en.wikipedia.org/wiki/Percent-encoding (and more relevant, to https://www.rfc-editor.org/rfc/rfc3986):

the data should first be encoded as octets according to the UTF-8 character encoding, then only those octets […] should be percent-encoded.

So, %C3%BA is the perfectly correct encoding of ú, which is not a character from the unreserved ASCII range.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Thanks, do you know any reason why a server might return ú instead of ú when this is passed in the url as a parameter using encodeURIComponent? – Malcr001 Jan 31 '14 at 02:32
  • Looks like the encoding in which he expects the URLs is misconfigured, but I don't know your server. It might as well be the response `Content-Type`… – Bergi Jan 31 '14 at 10:08