JS and ASCII codes

6 views
Skip to first unread message

Richard Langner

unread,
Feb 1, 2022, 3:08:19 PM2/1/22
to Sheffield Hardware Hackers
I'm running a javascript function in a webpage and viewing it with Firefox.

console.log("£ S");

The console prints £ S

The letter S is OK but the pound sign (ASCII code 163) is prefixed with a circumflexed A (ASCII code 194).

My guess is extended ASCII codes. What do I need to do to avoid this problem?
Could it be the javascript is sending it that way or perhaps the console monitor is showing it wrong?

Ideas gratefully received......

Adam Funk

unread,
Feb 1, 2022, 3:31:27 PM2/1/22
to sheffield-har...@googlegroups.com, Richard Langner
Hi,

That's a classic encoding discrepancy:

"£" encoded in utf-8 is 0xC2A3 (two bytes), but that 2-byte sequence
decodes in iso-latin-1 to "£" (the "£" is one byte 0xA3 in latin-1).

I'd guess that the javascript console is using the wrong encoding to
decode the bytes to a printable string.


HTH
Adam




On 01/02/2022 20:08, Richard Langner wrote:
> I'm running a javascript function in a webpage and viewing it with Firefox.
>
> console.log("£ S");
>
> The console prints*£ S*
>
> The letter S is OK but the pound sign (ASCII code 163) is prefixed with
> a circumflexed A (ASCII code 194).
>
> My guess is extended ASCII codes. What do I need to do to avoid this
> problem?
> Could it be the javascript is sending it that way or perhaps the console
> monitor is showing it wrong?
>
> Ideas gratefully received......
>
> --
> You received this message because you are subscribed to the Google
> Groups "Sheffield Hackspace" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sheffield-hardware-...@googlegroups.com
> <mailto:sheffield-hardware-...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/sheffield-hardware-hackers/21445534-ed24-abf4-7561-b74ec8c9332c%40gmail.com
> <https://groups.google.com/d/msgid/sheffield-hardware-hackers/21445534-ed24-abf4-7561-b74ec8c9332c%40gmail.com?utm_medium=email&utm_source=footer>.

James Muirhead

unread,
Feb 1, 2022, 4:16:43 PM2/1/22
to Sheffield Hackspace, Richard Langner
It's cos it's displaying in a web page. Change it to...

&#163;

Should fix it!

-OJ.

To unsubscribe from this group and stop receiving emails from it, send an email to sheffield-hardware-...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sheffield-hardware-hackers/c576a67b-4fe1-ff12-2057-570d8106f9ba%40ducksburg.com.

Richard Langner

unread,
Feb 1, 2022, 4:26:57 PM2/1/22
to James Muirhead, Sheffield Hackspace
Thanks OJ and Adam (although strange I didn't get Adams reply until this email).

I'm using websockets and JSON to communicate between browser and Wemos D1 mini webserver,  sending passwords which could contain the pound sign. I need to know whether it is getting converted or just displayed differently by Firefox's console.



On 01/02/2022 21:16, James Muirhead wrote:
It's cos it's displaying in a web page. Change it to...

&#163;

Should fix it!

-OJ.

James Muirhead

unread,
Feb 1, 2022, 4:35:28 PM2/1/22
to richard...@gmail.com, Sheffield Hackspace

I'd just avoid using anything above char 127 if it's a password!

-OJ

Richard Langner

unread,
Feb 1, 2022, 5:21:08 PM2/1/22
to James Muirhead, Sheffield Hackspace
That's a good point, but the AP we log onto may use odd characters for the SSID password.


On 01/02/2022 21:35, James Muirhead wrote:

I'd just avoid using anything above char 127 if it's a password!

-OJ

James Muirhead

unread,
Feb 1, 2022, 6:03:11 PM2/1/22
to richard...@gmail.com, Sheffield Hackspace

So you're using the default password?

-OJ

Richard Langner

unread,
Feb 2, 2022, 5:17:51 AM2/2/22
to Sheffield Hackspace
It seems my query was academic as a search revealed that allowable characters are:

ASCII 0x20, 0x21, 0x23, 0x25 through 0x2A, 0x2C through 0x3E, 0x40 through 0x5A, 0x5E through 0x7E.

The issue was due to my mistake of throwing in any old character to test the system!


On 01/02/2022 23:03, James Muirhead wrote:

So you're using the default password?

-OJ

Reply all
Reply to author
Forward
0 new messages