Skip to content

[bug] ANSI-C \u/\U escapes decoded regardless of locale: under LC_ALL=C GNU keeps the literal backslash-u text (uppercased hex), rubash emits UTF-8 bytes #353

Closed

Description

@caomengxuan666

Found by gnusweep3 lane (cat1 q013/q014; WSL GNU Bash 5.3.0 oracle, worktree 0fe8d0f).

Repro:

export LC_ALL=C
printf '%s\n' $'\u00e9'
printf '%s\n' $'\U000000e9'

GNU 5.3.0 under LC_ALL=C: prints the 6 literal characters \u00E9 (hex UPPERCASED — the escape is left unexpanded when the locale cannot represent it).
rubash: prints the UTF-8 bytes of é (0xC3 0xA9) — \u decoding ignores locale.

Distinct from #323 (that one is $'…' not decoded in the ${var//pat/repl} replacement operand — an expansion-position bug; this is the locale gate on the decoder itself).

GNU C owner: lib/sh/strtrans.c:51 ansicstr() — the \u/\U branch checks the locale (locale_mb_curmax / utf8 locale) before emitting the encoded character; non-UTF-8 locales keep the literal text.
Artifacts: target/issue-suites/results/gnusweep3/cat1/case/q013.* / q014.; minimal target/issue-suites/results/gnusweep3/probes/min/m21-ansi-u-locale.

Activity

  1. added
    bug
    gnu-baseline
    on Sep 30, 2026
  2. added 2 commits that reference this issue on Sep 30, 2026
  3. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt21/resid21 (495082eb, master d5d6642): landed the GNU read-time semantics rather than full deferred decode (which would touch every observable boundary — typed-carrier-class risk). GNU reads dollar-single-quote lists line by line and decodes each at READ time (parse.y:5560 ansiexpand), so export LC_ALL=C on a PREVIOUS line takes effect, while the same list/brace group/earlier-defined function body keeps the original locale — L1-L4c probes all byte-identical to WSL GNU. Implementation: thread-local decode-locale override; lexer value dispatch extracted verbatim to word_value_from_raw; WordMetadata records the lex-time locale (only words containing backslash-u escapes); executor records the per-line read-time locale; command words and assignment RHS (including the pure-assignment path that bypasses expand_command_words) re-derive under the line locale when they differ. nquote1-5/iquote/intl/new-exp/unicode byte-identical baseline vs fixed. Documented residual: for-in and case words still lex-time locale (rare family, untested-by-corpus).

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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions