Skip to content

fix(interpreter): count unicode chars in ${#x} and add printf \u/\U escapes#378

Merged
chaliy merged 1 commit intomainfrom
claude/fix-362-unicode-Vvs93
Feb 27, 2026
Merged

fix(interpreter): count unicode chars in ${#x} and add printf \u/\U escapes#378
chaliy merged 1 commit intomainfrom
claude/fix-362-unicode-Vvs93

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Feb 27, 2026

Summary

  • Fix ${#x} to count Unicode characters instead of bytes: x=café; echo ${#x} now correctly returns 4 instead of 5
  • Add \uHHHH (4-digit) and \UHHHHHHHH (8-digit) Unicode escape handling to the printf builtin, both in format strings and %b argument expansion
  • Remove 3 ### skip: markers from unicode.test.sh and replace with ### bash_diff: markers (system bash behavior differs based on locale)

Test plan

  • cargo fmt --check clean
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • All 1015 unit tests pass
  • Bash spec tests: 1184 passed, 0 failed (100% pass rate)
  • Bash comparison tests: 1081/1081 match real bash (100%)
  • New printf unicode unit tests: test_unicode_escape_u, test_unicode_escape_big_u, test_unicode_escape_ascii, test_unicode_escape_in_expand

Closes #362

@chaliy chaliy force-pushed the claude/fix-362-unicode-Vvs93 branch from a37a60a to e04a738 Compare February 27, 2026 23:14
…scapes

- Change ${#x} from .len() (byte count) to .chars().count() (character
  count) so `x=café; echo ${#x}` returns 4 instead of 5
- Add \uHHHH and \UHHHHHHHH unicode escape handling to printf format
  strings and %b expand_escapes
- Add parse_unicode_escape helper function to printf builtin
- Remove 3 ### skip: markers from unicode.test.sh, replace with
  ### bash_diff: for locale-dependent differences
- Add unit tests for printf unicode escapes

Closes #362
@chaliy chaliy force-pushed the claude/fix-362-unicode-Vvs93 branch from e04a738 to 1b44842 Compare February 27, 2026 23:26
@chaliy chaliy merged commit ef0c02d into main Feb 27, 2026
16 checks passed
@chaliy chaliy deleted the claude/fix-362-unicode-Vvs93 branch March 12, 2026 03:43
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.

Unicode: ${#x} counts bytes, printf \u/\U escapes missing

2 participants