Ty Kroll Ty Kroll - 9 months ago 68
Javascript Question

String gets mangled when passed from Grunt to CasperJS

I have a Gruntfile that can be executed from the command line with a string in Thai.

grunt --data=นี่คือการทดสอบ

When I echo the string, I can see, that the string is intact:


I then spawn a CasperJS script with the string

cmd: '/usr/local/bin/casperjs',
args: [
'--text=' + str,
function(error, result, code)
grunt.log.writeln(error + ' | ' + result + ' | ' + code);

But echoing it now gives me a mess:


The plot thickens: I'm running this all from cloud-init via userdata on an AWS instance.
However, when I run the same Grunt command via the shell, the scripts work fine. - Any ideas?

Answer Source

Figured this out.

The bytes encoding changed coming into Casper from Grunt.

Ran them through utf8to16 from http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt

All good to go.