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

Handle invalid UTF-8 in source code #393

Merged
merged 2 commits into from
Aug 8, 2024
Merged

Conversation

Porges
Copy link
Contributor

@Porges Porges commented Aug 5, 2024

At the moment if invalid UTF-8 is passed to the source code, then the Report will panic when rendered. This PR changes it to properly decode UTF-8 and handle the invalid data in the usual way (i.e. they will be replaced with �).

This can require an extra allocation when rendering Report, but only for invalid UTF-8, and only for the "context" area, which is usually small (several lines).

This is simply a one-line change, but there are tests to double-check the behaviour of offsets into invalid source. I added some tests for labels into "good" Unicode source and also into "bad" Unicode source. Both seem to behave as expected.

× decoding error
╭────
1 │ malformed h�XYZ
· ┬
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correctly pointing at the X, although it is hard to tell from the Github preview.

@zkat
Copy link
Owner

zkat commented Aug 5, 2024

what's the deal with clippy. sigh.

@waywardmonkeys
Copy link
Contributor

@zkat I've got clippy fixed in PR #395.

@zkat
Copy link
Owner

zkat commented Aug 6, 2024

awesome thanks. You can rebase now.

@Porges
Copy link
Contributor Author

Porges commented Aug 8, 2024

@zkat awesome thanks. You can rebase now.

Fixed the 1.70 build as well. Should be good to go.

@zkat zkat merged commit d6b4558 into zkat:main Aug 8, 2024
15 checks passed
@Porges Porges deleted the invalid_unicode branch August 8, 2024 23:25
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.

3 participants