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

Detecting a UTF-8 string with control characters leads to unexpected behavior #49

Open
ruicc opened this issue Sep 27, 2024 · 0 comments

Comments

@ruicc
Copy link

ruicc commented Sep 27, 2024

import Encoding from 'encoding-japanese';

const bs = Buffer.from(new Uint8Array([0x08]));
console.log('detect("<BS>"):', Encoding.detect(bs));

const utf8str = Buffer.from("UTF8の文字列です", 'utf8');
console.log('detect("UTF8の文字列です"):', Encoding.detect(utf8str));

const utf8BS = Buffer.concat([utf8str, bs]);
console.log('detect("UTF8の文字列です<BS>"):', Encoding.detect(utf8BS));

output:

detect("<BS>"): ASCII
detect("UTF8の文字列です"): UTF8
detect("UTF8の文字列です<BS>"): UNICODE

I think the final result can be "UTF8" because UTF-8 includes ASCII.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant