Locale-Sensitive JavaScript Method
encodeURI(string);
Internationalization (I18n) Method Overview
The encodeURI method encodes a URI (Uniform Resource Identifier), replacing specific characters with their hexadecimal UTF-8 encoded values,
with up to 3 encoded values representing characters from the Basic Multilingual Plane (BMP). When the character is outside the BMP, the high and low surrogate
characters are encoded using 4 UTF-8 encoded values.
In the following example, the Chinese characters and spaces have been replaced with their hexadecimal UTF-8 encoded values:
var str = "test.html?name1=漢One Two&name2=𠀐Three";
var result = encodeURI(str);
Method returns:
result: test.html?name=%E6%BC%A2One%20Two&name2=%F0%A0%80%90Three
Click here (w3schools) and
here (MDN) for additional details.
I18n Issues
encodeURI does not encode characters such as &, +, = . This is a problem for HTTP Get and Post requests, which treats these
as special characters. Therefore, if you have user text being passed as a parameter, and it contains any of these special characters, the HTTP request will interpret the URI
incorrectly.
Suggested Replacement
To ensure that the URI is properly encoded to work in HTTP Get and Post requests, call encodeURIComponent .
And then, to decode the URI, call decodeURIComponent .
Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can
use Globalyzer's Ignore Comment
functionality to ensure that it isn't picked up in a subsequent scan.
Locale-Sensitive JavaScript Methods
|