Skip to content

Remove invalid characters after decoding #26

@metapone

Description

@metapone

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions