Ty Kroll Ty Kroll - 1 year ago 105
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download