Skip to content

text: report byte offset in UnescapeError::BadEscape - #738

Open
Divyansh151005 wants to merge 1 commit into
anthropics:mainfrom
Divyansh151005:text/unescape-error-offset-648
Open

Divyansh151005 wants to merge 1 commit into
anthropics:mainfrom
Divyansh151005:text/unescape-error-offset-648

Conversation

@Divyansh151005

Copy link
Copy Markdown
Contributor

Fixes #648

What this does

  • UnescapeError::BadEscape becomes { reason, offset } (breaking API, as discussed on the issue). Display includes the byte offset into the literal token.
  • TextDecoder::read_string / read_bytes add that offset to tok.pos before computing line/column, so adjacent literals no longer report errors at the first quote.
  • Tests cover direct unescape_str on a two-literal token and decode_from_str on the issue-shaped input.

Testing

rustc 1.95.0 (rust-toolchain.toml)
cargo fmt --check
cargo clippy -p buffa --features text -- -D warnings
cargo test -p buffa --features text unescape
cargo test -p buffa --features text second_concatenated

All passed locally.

Fixes anthropics#648

BadEscape is now { reason, offset } with offset in Display. TextDecoder
adds the offset to the token start when mapping to ParseError so a bad
escape in a later concatenated literal gets the correct line and column.
@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

This branch has not been deployed

No deployments
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.

text: a bad escape is reported at the start of the string literal, and UnescapeError carries no offset

1 participant