📜 ⬆️ ⬇️

Novice Error: Encode URI in UTF-8.

In the process of mastering an extremely simple, but all the more unusually important and ineptly written frivolous ajax-library of comments Ajax Generic Comments Module , I came across an interesting and non-obvious effect for me. Comments of some users on my site were displayed correctly, and comments of others in the form of habrassyabr. The default site encoding is utf-8. But the posts of some users appeared in cp1251. I tried to repeat the bug, but could not do it in any of the browsers installed on my system. (Installed Linux Debian - that was my mistake. Browsers: Opera 9, FireFox, Konqueror.) Without testing libu in only one of the famous browsers, I realized that the worst fears come true. Launched Internet Explorer 6.0 and - eureka. (There is a way to run Internet Explorer on Linux - IEs4Linux )



Note. All non-latin characters included in the URI must be encoded in UTF-8. Those. The URI for which the request will be made should look like this saveComment.php? CommentText =% DD% FF% AA ...
')
As a result, I came to the conclusion that all popular browsers, with the exception of Internet Explorer, automatically encode the requested url in utf-8. In the case of the donkey, use the javascript :: encodeURI (url) function immediately before calling XMLHttpRequest.open (). In general, it is always better to use it. :) You can read about other functions for converting to Unicode here .

Source: https://habr.com/ru/post/23687/


All Articles