Skip to content

Keep invalid source bytes out of syntax error annotations - #267

Open
adityawrk wants to merge 1 commit into
ruby:mainfrom
adityawrk:fix/invalid-encoding-annotation
Open

adityawrk wants to merge 1 commit into
ruby:mainfrom
adityawrk:fix/invalid-encoding-annotation

Conversation

@adityawrk

@adityawrk adityawrk commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #258.

When a source file contains bytes that are illegal in the current encoding, the annotation copied those bytes into the syntax error. Under LC_ALL=C the message becomes an invalid US-ASCII string, so a later match on the error text raises ArgumentError. A UTF-16 file with a BOM is the case from the Ruby source-encoding specs: the annotation printed the raw 0xFF byte.

SyntaxSuggest.call now leaves that source alone, and an empty annotation is not prepended to the original message. A normal syntax error in a valid encoding is still annotated.

Under LC_ALL=C, the UTF-16 file's detailed message is valid US-ASCII and no longer contains 0xFF. Specs: 171 examples, 0 failures. The executable version example compares against the syntax_suggest already loaded by this Ruby, which is 2.0.3, so it was not part of that count.

A file whose bytes are illegal in the current encoding was copied into
the annotation. Under a C locale that made the message an invalid
US-ASCII string. Those sources are now left to the original message.
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.

SyntaxSuggest 3.0.0 leaks raw invalid bytes into stderr when source has invalid encoding

1 participant