I have cgi script pulling search terms from an HTML form through CGI::Ajax. When running Encode::Detect::Detector over the resulting string in my script, I get, instead of just UTF-8, a variety of encodings depending on the characters entered in the form: Greek chars turn up as UTF-8, umlauts as windows-1252 and no output at all for ASCII characters. I am fairly sure the problem lies with whatever CGI::Ajax does to the string it passes to Perl. It uses decodeURI() somewhere in its code, I have tried URI::Escape and Encode in all possible permutations, but none of my attempts to normalise the different strings to a single encoding were successful. As it is, one or the other set of non-ASCII chars (either umlauts or the Greek) will always be garbled. How do I tell Ajax to keep it Unicode?
I have cgi script pulling search terms from an HTML form through CGI::Ajax .
Share
Solved:
CGI::Ajaxapparently uses Javascript’sescapefunction, which does not handle Unicode correctly. The function has been superseded byencodeURIandencodeURIComponent, which can be set as the default escaping functions for anCGI::Ajaxobject$pjxlike so:$pjx->js_encode_function('encodeURIComponent');. Phew.