Skip to content

fix(interpreter): ${#v} counts bytes under the C locale - #2627

Merged
chaliy merged 1 commit into
mainfrom
claude/c-locale-length
Oct 8, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/c-locale-length

Conversation

@chaliy

@chaliy chaliy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

  • ${#v} counts bytes when the shell's locale is C or POSIX, read from LC_ALL, then LC_CTYPE, then LANG (first non-empty), as bash does. local LC_ALL=... scopes it like any variable.
  • ${#v} inside a default operand (${x:-${#s}}) counted bytes in every locale; it now counts characters like the top-level form.

Why

Bash-oracle gap unicode-and-bytes. Agent scripts set LC_ALL=C for fast sort/grep and then size strings; bashkit reported characters where bash reports bytes.

Before / After

$ LC_ALL=C; s=ação; echo ${#s}
before: 4      after: 6      (bash 5.2: 6)
$ s=ação; echo ${x:-${#s}}
before: 6      after: 4      (bash 5.2: 4)

New spec c-locale-length.test.sh (5 cases, checked against bash 5.2 and by bash_comparison_tests).

Risk

Low. With no locale variable set bashkit stays UTF-8 (bash would fall back to C). Slices, case changes and globs stay character-based under C because shell words cannot hold a split UTF-8 sequence; documented in limitations ("Locale").

Checklist

  • fmt, clippy -D warnings
  • integration and lib tests, bash_comparison_tests
  • knowledge (log.md, limitations)

Generated by Claude Code

@chaliy chaliy self-assigned this Oct 8, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit e68f9f4 Commit Preview URL

Branch Preview URL
Oct 08 2026, 03:00 AM

@chaliy
chaliy force-pushed the claude/c-locale-length branch from 06ac3fc to 7eac9dd Compare October 8, 2026 02:14
LC_ALL, LC_CTYPE, LANG (first non-empty) set to C or POSIX make ${#v}
count bytes like bash. ${#v} inside a ${x:-...} operand counted bytes in
every locale and now counts characters.
@chaliy
chaliy force-pushed the claude/c-locale-length branch from 7eac9dd to e68f9f4 Compare October 8, 2026 02:59
@chaliy
chaliy merged commit a64316b into main Oct 8, 2026
46 checks passed
@chaliy
chaliy deleted the claude/c-locale-length branch October 8, 2026 03:40
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.

1 participant