Sample code on PuckJS that is causing issues if not escaped when sending to a Espruino device after two times E.toJS
var aJS5 = {txt : "012345\nabcde\näöüß"};
var saJS5 = E.toJS(aJS5);
//"{txt:\"012345\\nabcde\\n\\xE4\\xF6\\xFC\\xDF\"}"
var sa2JS5 = E.toJS(saJS5);
// "{txt:\"012345\\nabcde\\n\\xE4\\xF6\\xFC\\xDF\"}" // same
var COMMAND = `\x03\x10transfer(${sa2JS5})\n`;
// transfer("{txt:\"012345\\nabcde\\n\\xE4\\xF6\\xFC\\xDF\"}") <- cause syntax error
var saJS5e = E.toJS(aJS5).replace(/\\n/g,'\\\\n').replace(/\\x/g,'\\\\x');
// "{txt:\"012345\\\\nabcde\\\\n\\\\xE4\\\\xF6\\\\xFC\\\\xDF\"}";
var COMMAND = `\x03\x10transfer(${saJS5e})\n`;
// "\3\x10transfer({txt:\"012345\\\\nabcde\\\\n\\\\xE4\\\\xF6\\\\xFC\\\\xDF\"})\n"; // <- no error
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sample code on PuckJS that is causing issues if not escaped when sending to a Espruino device after two times
E.toJS