You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
text: a bad escape is reported at the start of the string literal, and UnescapeError carries no offset #648
buffa::text::unescape_str(r#""abc\q""#)// Err: unrecognised escape sequence
buffa::text::decode_from_str::<StringValue>("value: \"abc\"\n\"def\\q\"")// Err: text format parse error (line 1:8): invalid string: unrecognised escape sequence
The bad escape in the second input is on line 2. The error points at the opening quote of the first literal, because adjacent literals are one token and the decoder reports the token's position (TextDecoder::read_string and read_bytes, buffa/src/text/decoder.rs:454-481). UnescapeError::BadEscape(&'static str) holds only a fixed reason (buffa/src/text/string.rs:35-45), so neither the decoder nor a direct caller of unescape / unescape_str can say where in the literal the failure is, or which sequence caused it.
Proposed: record the byte offset of the offending backslash within raw, print it in Display, and have the decoder add it to the token position before it computes line and column. UnescapeError is a public enum without #[non_exhaustive], so a new field on BadEscape is a breaking change and belongs in a minor release.
Plan: extend UnescapeError::BadEscape with a byte offset into the token raw (breaking API, as noted in the issue). Thread offsets through unescape / unescape_str, include the offset in Display, and in TextDecoder::read_string / read_bytes add that offset to tok.pos before line_col. Tests: direct unescape on a concatenated literal, plus decode_from_str pointing at the second literal's bad escape (issue example).
Activity
Divyansh151005 commentedon Oct 17, 2026
I'll take this.
Plan: extend
UnescapeError::BadEscapewith a byte offset into the tokenraw(breaking API, as noted in the issue). Thread offsets throughunescape/unescape_str, include the offset inDisplay, and inTextDecoder::read_string/read_bytesadd that offset totok.posbeforeline_col. Tests: direct unescape on a concatenated literal, plusdecode_from_strpointing at the second literal's bad escape (issue example).text: report byte offset in UnescapeError::BadEscape