Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode characters are mangled in JavaScript kata output #307

Closed
paul-calvelage opened this issue May 18, 2016 · 3 comments
Closed

Unicode characters are mangled in JavaScript kata output #307

paul-calvelage opened this issue May 18, 2016 · 3 comments

Comments

@paul-calvelage
Copy link

Unicode characters in the JavaScript kata output are being mangled.

Each byte of the UTF-8 encoding seems to be printing as a separate Unicode character. So the Chinese greeting 你好 displays as ä½ å¥½.

This is very bad for anyone needing more than 7-bit ASCII.

Now for some examples of what I think may be happening. This code in a JavaScript kata:

console.log("£");

displays as the two characters £ ("\u00c2\u00a3"). The Unicode code point for £ ("\u00a3") is normally encoded in UTF-8 as 0xc2a3. But Codewars apparently re-encodes each byte: 0xc2, 0xa3 to get £.

This:

console.log("\uffff")

is displayed as three characters ï¿¿ ("\u00ef\u00bf\u00bf"). The Unicode code point 0xffff is normally encoded in UTF-8 as 0xefbfbf. But as above, Codewars then seems to re-encode 0xef, 0xbf, 0xbf to ï¿¿.

I could give as many examples as there are multiple-byte UTF-8 encodings, but this suffices to show the pattern for a single character. Longer strings just repeat the problem, so that console.log("£££££"); displays as £££££ for example.

As I said, this seems to be pretty serious for anyone needing Unicode.


Note: I discovered this while completing Simple Change Machine, which uses the pound symbol.

@paul-calvelage
Copy link
Author

The Chinese Numeral Encoder kata has lots of Unicode characters, so it is affected by this bug. In this screenshot it is noticeable in the test output.
example

@paul-calvelage
Copy link
Author

My previous screenshot was in Chrome on Windows 10. In Firefox I get a slightly different (but still incorrect) output:
firefox

@kazk
Copy link
Member

kazk commented Aug 25, 2017

#902

@kazk kazk closed this as completed Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants