Skip to content

fix: implement missing parameter expansion and fix output mismatches#112

Merged
chaliy merged 3 commits intomainfrom
claude/fix-output-tests-7ANdl
Feb 3, 2026
Merged

fix: implement missing parameter expansion and fix output mismatches#112
chaliy merged 3 commits intomainfrom
claude/fix-output-tests-7ANdl

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 3, 2026

Summary

This PR fixes several output mismatches between bashkit and bash, implementing missing parameter expansion features and fixing sed backreference handling.

Changes

  1. Printf zero-padding support (%05d, %5s, etc.)

    • Added FormatSpec struct to parse and apply format specifications
    • Supports zero-padding, width, precision, and left-alignment
    • Added comprehensive printf spec tests
  2. Advanced parameter expansion features

    • Substring extraction: ${var:offset} and ${var:offset:length}
    • Array slicing: ${arr[@]:offset:length}
    • Pattern replacement: ${var/pattern/replacement} and ${var//pattern/replacement}
    • Case conversion: ${var^^}, ${var^}, ${var,,}, ${var,}
    • Indirect expansion: ${!var}
  3. Sed backreference fix

    • Fixed regex replacement syntax to use ${N} format instead of $N
    • This prevents the regex crate from interpreting $1p as named group "1p"

Tests

  • All existing tests pass
  • Added 19+ new spec tests for the new features
  • 100% bash comparison compatibility maintained (342/342 tests)

Fixed Issues

Issue Before After
${arr[@]:1:3} Raw string output 2 3 4
${x:0:5} Raw string output hello
${x/world/bash} hello_world hello_bash
${!a} Empty value
${x^^} hello HELLO
${x,,} HELLO hello
printf "%05d" 42 42 00042
sed 's/\(hel\)lo/\1p/' Empty help

Test plan

  • cargo test --package bashkit - all tests pass
  • cargo clippy - no warnings
  • cargo fmt --check - properly formatted
  • Bash comparison tests pass (100%)

https://claude.ai/code/session_016yoAaoZG7vPMbs97kbXqZb

Adds proper support for printf format specifications:
- Zero-padding with %05d style formats
- Width specifications (%5d, %5s)
- Left-alignment with %-5d
- Precision for floats (%.2f)
- Sign prefix with %+d

Adds FormatSpec struct to parse and apply format specifications
to all numeric and string format types.

Adds comprehensive printf spec tests covering all format features.

https://claude.ai/code/session_016yoAaoZG7vPMbs97kbXqZb
Adds support for several bash parameter expansion features:

- Substring extraction: ${var:offset} and ${var:offset:length}
- Array slicing: ${arr[@]:offset:length}
- Pattern replacement: ${var/pattern/replacement} and ${var//pattern/replacement}
- Case conversion: ${var^^}, ${var^}, ${var,,}, ${var,}
- Indirect expansion: ${!var}

Adds new AST variants:
- WordPart::Substring for variable substring extraction
- WordPart::ArraySlice for array slicing
- WordPart::IndirectExpansion for indirect variable lookup
- ParameterOp variants for replacement and case conversion

Includes comprehensive tests for all new features.

https://claude.ai/code/session_016yoAaoZG7vPMbs97kbXqZb
The regex crate interprets $1p as a named capture group "1p" instead
of capture group 1 followed by literal "p". This caused backreferences
like \1 followed by text to produce empty results.

Fixed by using ${N} format instead of $N format when converting sed
backreferences to regex replacement syntax.

Adds test for single backreference and enables the previously skipped
sed_backref_1 test.

https://claude.ai/code/session_016yoAaoZG7vPMbs97kbXqZb
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chaliy chaliy merged commit d4f4011 into main Feb 3, 2026
8 checks passed
@chaliy chaliy deleted the claude/fix-output-tests-7ANdl branch February 3, 2026 05:19
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.

2 participants