Skip to content

Lexer: unknown string escapes silently drop the backslash — \u{...} produces literal text #929

Closed

Description

@ehartford

Cost a debugging round in the #921 workspace campaign: \u{0} in an argv-builder produced the literal four characters u{0} instead of NUL (or an error), so the exec blob was silently garbage and the child never ran.

Behavior

with -e 'print("A=[\u{41}] q=[\q] x=[\x41]")'
→ A=[u{41}] q=[q] x=[A]

Any unknown escape drops the backslash and keeps the rest as literal text. \x41 is supported; \u{...} is not; \q and every other unknown escape pass silently.

Expected

An unknown escape sequence is a compile error, not silent text. Rust errors on unknown escapes; C6 warns-by-default and gcc/clang error under -Werror; Zig errors. Silent transformation is the worst of the options — the written program and the running program disagree with no diagnostic, in exactly the kind of low-level string (argv blobs, wire formats) where a wrong byte is invisible until a subprocess mysteriously fails.

Two separable pieces:

  1. Unknown escape → hard error (the footgun fix).
  2. Optionally, support \u{...} as the Unicode escape alongside \x — it's the spelling both Rust and Swift readers expect; without it, the error message from (1) should suggest \x or a literal.

Spec: §string literals should enumerate the accepted escapes; the mission's "fail loudly" doctrine (No Silent Fallbacks) applies to the lexer as much as codegen.

Activity

  1. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Fixed in 8034b3d. parse_string_literal validates every escape against the set the three decoders agree on (\n \t \r \0 \\ \" \' \{ \} \xHH) and errors with the offending two characters plus the supported list (rendered from the same set). Raw strings and f-string hole expressions are untouched.

    The sweep the check enables found two live instances in our own tree: tools/migrate_seams.w joined argv with "\u{1}" (four literal characters, never byte 1), and build/compiler.w spelled § as C octal \302\247, rendering as the text 30224714.19 roadmap. Both fixed in the same commit.

    Also fixed while pinning \{: the f-string desugar checked {{ before the backslash escape, so f"\{{x}" was the literal text {x; \{ now wins when its backslash is unescaped (odd run), so f"\\{{x}}" still means backslash, brace, x, brace.

    Fixtures: err_string_unknown_escape, err_string_unknown_escape_letter, behav_string_known_escapes. Battery green, reseeded.

  2. added a commit that references this issue on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions