Decode special characters from js to html

Hello everyone,
I need to pop-up and write on a text sheet from an error belonging to the command prompt.
This message may contain special characters such as è or ' but any special characters is encoded in ' or Š.
There is a function to decode it ? What I'm missing?

This is an example that reproduces the problem.

[{"id":"51ded00a.a1a3d","type":"inject","z":"48ee4f2c.7f99e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ID Device: 18 Error: 200.200.4.41ÿ: Il nome computer immesso non Š valido oppure l'arresto remoto non Š supportato nel computer di destinazione. Verificare di aver specificato il nome corretto e riprovare oppure contattare l'amministratore di sistema.(53)","payloadType":"str","x":2720,"y":3060,"wires":[["3e74bbc9.7e2724"]]},{"id":"3e74bbc9.7e2724","type":"function","z":"48ee4f2c.7f99e","name":"","func":"msg.uffa = toString(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3080,"y":3040,"wires":[["76a84ef7.15347","5ebea30e.27250c"]]},{"id":"76a84ef7.15347","type":"ui_toast","z":"48ee4f2c.7f99e","position":"dialog","displayTime":"5","highlight":"","sendall":false,"outputs":1,"ok":"OK","cancel":"","raw":false,"topic":" Error","name":"","x":3390,"y":2980,"wires":[[]]}]

Does it work if you tell the node to allow raw html?

image

1 Like

Not works

Doesn't it fix the '?

I think the problem with the unprintable unicode chars is that the browser font doesn't support them, but I am not sure.

No not even the ' character, I find the problem even when I write on a sheet of text: :confused:

Admin edit: added backticks round the html entities so they display properly/

It fixes that for me. What version of node-red and node-red-dashboard are you using? If you aren't using the latest dashboard then update it. Restart node-red and clear the browser cache (via the browser menus) after upgrading the dashboard.

My mistake it fix the ' character in the dashboard but don't fix the "è" character. I think it depends on the encoding (ASCII, UTF, ecc...) but I dont't know how to change it

The characters in the inject node are not "è". I don't know what they are. Try it with this inject node, where I have copied/pasted from here into the node.

[{"id":"51ded00a.a1a3d","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Testing:  è  -- ID Device: 18 Error: 200.200.4.41ÿ: Il nome computer immesso non Š valido oppure l'arresto remoto non Š supportato nel computer di destinazione. Verificare di aver specificato il nome corretto e riprovare oppure contattare l'amministratore di sistema.(53)","payloadType":"str","x":130,"y":2120,"wires":[["3e74bbc9.7e2724"]]}]


So the error is in the exec node ? he replaces me the è character with Š

[{"id":"1fbe759.9bbb08a","type":"template","z":"938038fa.b84288","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"shutdown /s /m 200.200.1.30 /t 0","output":"str","x":620,"y":960,"wires":[["db063984.f20b68"]]},{"id":"db063984.f20b68","type":"exec","z":"938038fa.b84288","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Shutdown","x":760,"y":960,"wires":[["d6cb8218.95979"],["d6cb8218.95979"],["d6cb8218.95979"]]},{"id":"d6cb8218.95979","type":"debug","z":"938038fa.b84288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":1000,"wires":[]},{"id":"a4c44518.10caa8","type":"inject","z":"938038fa.b84288","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":470,"y":960,"wires":[["1fbe759.9bbb08a"]]}]

If you create a Buffer object from the string then you will be able to see exactly what is in there.

image

The result is "194"

this is the code used

[{"id":"1fbe759.9bbb08a","type":"template","z":"938038fa.b84288","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"shutdown /s /m 200.200.1.30 /t 0","output":"str","x":620,"y":960,"wires":[["db063984.f20b68"]]},{"id":"db063984.f20b68","type":"exec","z":"938038fa.b84288","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Shutdown","x":760,"y":960,"wires":[[],["fae43cf0.fe304"],[]]},{"id":"d6cb8218.95979","type":"debug","z":"938038fa.b84288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":960,"wires":[]},{"id":"a4c44518.10caa8","type":"inject","z":"938038fa.b84288","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":470,"y":960,"wires":[["1fbe759.9bbb08a"]]},{"id":"fae43cf0.fe304","type":"function","z":"938038fa.b84288","name":"","func":"\n\n\n\nvar buf = Buffer.from(msg.payload.slice(40, 49));\n\nreturn [{payload: buf}, {payload:msg.payload.slice(40, 49)}];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":900,"y":960,"wires":[["d6cb8218.95979"],["d6cb8218.95979"]]}]

out of curiosity if you type the command you are trying to execute directly in the terminal / command prompt
shutdown /s /m 200.200.1.30 /t 0
does the reply message show correctly there ?
what OS are you using for Node-red server ?

Yes, I visualize the correct message.
Windows 7 on a virtual machine.
I use node red on the same machine.

Try this suggestion from stackoverflow
adding cmd /c chcp 65001>nul && before your command

Example:

[{"id":"cda367754c51905c","type":"template","z":"5847b7aa62131d37","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"cmd /c chcp 65001>nul && echo aaaaaaèèèèèèèèèèèèè","output":"str","x":440,"y":1440,"wires":[["9aca66bfab5dd96e"]]},{"id":"9aca66bfab5dd96e","type":"exec","z":"5847b7aa62131d37","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"Shutdown","x":580,"y":1440,"wires":[["66beee34a5657518"],[],[]]},{"id":"251f7d8f58af3349","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":1440,"wires":[["cda367754c51905c"]]},{"id":"66beee34a5657518","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":1400,"wires":[]}]

or ( /u forces unicode)

cmd /u /c echo aaaaaaèèèèèèèèèèèèè

Example:

[{"id":"cda367754c51905c","type":"template","z":"5847b7aa62131d37","name":"unicode","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"cmd /u /c echo aaaaaaèèèèèèèèèèèèè","output":"str","x":420,"y":1220,"wires":[["9aca66bfab5dd96e"]]},{"id":"9aca66bfab5dd96e","type":"exec","z":"5847b7aa62131d37","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"Shutdown","x":580,"y":1260,"wires":[["c72c16ef850e5404","cfa7f01104df371c"],[],[]]},{"id":"251f7d8f58af3349","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":1220,"wires":[["cda367754c51905c"]]},{"id":"66beee34a5657518","type":"debug","z":"5847b7aa62131d37","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":1240,"wires":[]},{"id":"9ceab32ac55c22e6","type":"template","z":"5847b7aa62131d37","name":"non unicode","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"echo aaaaaaèèèèèèèèèèèèè","output":"str","x":410,"y":1300,"wires":[["9aca66bfab5dd96e"]]},{"id":"06edacc4bbb7ddbc","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":260,"y":1300,"wires":[["9ceab32ac55c22e6"]]},{"id":"c72c16ef850e5404","type":"function","z":"5847b7aa62131d37","name":"","func":"msg.payload = msg.payload.toString(\"utf16le\") \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":1240,"wires":[["66beee34a5657518"]]},{"id":"cfa7f01104df371c","type":"debug","z":"5847b7aa62131d37","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":1180,"wires":[]}]

With the examples I display the right character but using my command the answer still gives me a wrong character

and what if you replace the command to execute with powershell instead ?

powershell -command "shutdown /s /m 200.200.1.30 /t 0"

also have tried changing the settings in Windows for Region (Language for non-Unicode programs)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.