# Decode special characters from js to html

**URL:** <https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512>\
**Category:** General\
**Created:** [10 November 2021 14:48 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512 "2021-11-10T14:48:56Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [10 November 2021 14:48 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/1 "2021-11-10T14:48:56Z")

</div>

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.

```auto
[{"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&#39;arresto remoto non  supportato nel computer di destinazione. Verificare di aver specificato il nome corretto e riprovare oppure contattare l&#39;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":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 November 2021 15:55 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/2 "2021-11-10T15:55:25Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/18b850903f2b5ed317765c93f715867e17919a79.png)

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [10 November 2021 15:59 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/3 "2021-11-10T15:59:08Z")

</div>

Not works

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 November 2021 16:07 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/4 "2021-11-10T16:07:28Z")

</div>

Doesn't it fix the `&#39;`?

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

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [10 November 2021 16:36 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/5 "2021-11-10T16:36:49Z")

</div>

No not even the `&#39;` character, I find the problem even when I write on a sheet of text: 😕

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 November 2021 16:55 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/6 "2021-11-10T16:55:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [10 November 2021 17:18 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/7 "2021-11-10T17:18:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 November 2021 17:25 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/8 "2021-11-10T17:25:42Z")

</div>

> [@Giu-seppe](#):
>
> but don't fix the "è" character

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.

```auto
[{"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&#39;arresto remoto non  supportato nel computer di destinazione. Verificare di aver specificato il nome corretto e riprovare oppure contattare l&#39;amministratore di sistema.(53)","payloadType":"str","x":130,"y":2120,"wires":[["3e74bbc9.7e2724"]]}]

```

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [11 November 2021 08:35 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/9 "2021-11-11T08:35:22Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/261ccc6474154feaa4d8091d385e6aec529026e7.png)  
So the error is in the exec node ? he replaces me the è character with Š

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 November 2021 09:01 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/10 "2021-11-11T09:01:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [11 November 2021 09:20 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/11 "2021-11-11T09:20:18Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/baf1f96b1e92ac484ffca66ad5d02a1cbd6a1bdf.png)

The result is "194"

this is the code used

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [11 November 2021 09:34 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/12 "2021-11-11T09:34:02Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [11 November 2021 09:39 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/13 "2021-11-11T09:39:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [11 November 2021 10:52 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/14 "2021-11-11T10:52:52Z")

</div>

~~Try this suggestion from [stackoverflow](https://stackoverflow.com/questions/20731785/wrong-encoding-when-using-child-process-spawn-or-exec-under-windows)  
adding `cmd /c chcp 65001>nul &&` before your command~~

 

**Example:**

```auto
[{"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:**

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Giu-seppe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/giu-seppe/32/40489_2.png) [@Giu-seppe](https://discourse.nodered.org/u/Giu-seppe)\
**Post date:** [12 November 2021 15:52 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/15 "2021-11-12T15:52:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [12 November 2021 16:40 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/16 "2021-11-12T16:40:55Z")

</div>

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](https://stackoverflow.com/questions/388490/how-to-use-unicode-characters-in-windows-command-line))

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d31cfed1c3704e9110f146658acc8220bbf90b72.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 January 2022 16:40 UTC](https://discourse.nodered.org/t/decode-special-characters-from-js-to-html/53512/17 "2022-01-11T16:40:56Z")

</div>

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