Skip to content

fix: refuse a json5 comment that is not valid utf-8 - #546

Merged
josegonzalez merged 1 commit into
mainfrom
544-fmt-panics-converting-a-json5-comment-that-is-not-valid-utf-8
Sep 16, 2026
Merged

josegonzalez merged 1 commit into
mainfrom
544-fmt-panics-converting-a-json5-comment-that-is-not-valid-utf-8

Conversation

@josegonzalez

Copy link
Copy Markdown
Member

The lexer keeps a comment's bytes verbatim, which is what lets fmt carry one across a conversion, and nothing between there and yaml.v3's emitter checked that they were text: a comment is written out raw and the writer panics outright on a byte that starts no rune, so docket fmt --format yaml died rather than reporting a problem with the file. A comment is now screened as it is lexed, and the file refused with the offending byte and its offset. A string value needs no such screen and does not get one, since an invalid byte there already reads as U+FFFD, which is what the loader reads it as.

Closes #544

The lexer keeps a comment's bytes verbatim, which is what lets `fmt` carry one across a conversion, and nothing between there and yaml.v3's emitter checked that they were text: a comment is written out raw and the writer panics outright on a byte that starts no rune, so `docket fmt --format yaml` died rather than reporting a problem with the file. A comment is now screened as it is lexed, and the file refused with the offending byte and its offset. A string value needs no such screen and does not get one, since an invalid byte there already reads as U+FFFD, which is what the loader reads it as.
@josegonzalez
josegonzalez merged commit 6c89694 into main Sep 16, 2026
19 checks passed
@josegonzalez
josegonzalez deleted the 544-fmt-panics-converting-a-json5-comment-that-is-not-valid-utf-8 branch September 16, 2026 16:39
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.

fmt panics converting a JSON5 comment that is not valid UTF-8

1 participant