Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top