Skip to content

Handle invalid encoded strings #28

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

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

Earlopain
Copy link
Contributor

When trying to calculate the width of such strings, it would previously crash with either Encoding::InvalidByteSequenceError or Encoding::UndefinedConversionError. Totally invalid characters are now simply replaced with a replacement character when converting to UTF8.

Especially binary encoded strings (i.e. no encoding) don't make much sense but at least it doesn't crash now and tries to return a sensible default (assume the string is actually valid UTF8

This if for rubocop/rubocop#13618, where such strings started to fail after unicode-display_width v3.

When trying to calculate the width of such strings, it would previously
crash with either `Encoding::InvalidByteSequenceError` or
`Encoding::UndefinedConversionError`. Totally invalid characters are now simply
replaced with a replacement character when converting to UTF8.

Especially binary encoded strings (i.e. no encoding) don't make much sense but at least it doesn't
crash now and tries to return a sensible default (assume the string is actually valid UTF8
@janlelis janlelis merged commit a23a070 into janlelis:main Dec 26, 2024
@janlelis
Copy link
Owner

Thank you, good workarounds!

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

Successfully merging this pull request may close these issues.

2 participants