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

Remove invalid characters after decoding #26

Open
metapone opened this issue Oct 26, 2021 · 0 comments
Open

Remove invalid characters after decoding #26

metapone opened this issue Oct 26, 2021 · 0 comments

Comments

@metapone
Copy link

metapone commented Oct 26, 2021

In the case of an invalid array input when converting to Unicode, currently encoding.js output the invalid bytes as normal question marks (char code 63), so I can't remove invalid characters from the result without accidentally remove valid question marks. Can you ask an option to remove invalid characters after decoding, or at least use a special character instead of question mark as a placeholder for invalid result characters?

Sample code:

const targetBytes = encoding.convert(
  '??',
  {
    to: 'SJIS',
    type: 'array',
  }
);
const result = encoding.convert(targetBytes.slice(0, 2), {
  to: 'UNICODE',
  from: 'SJIS',
  type: 'string',
});

Result: ??. Both characters are ? even though the last one should be an invalid character.

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