Skip to content

fix(interpreter): parse arithmetic parameter operators at first operator - #1472

Merged
chaliy merged 1 commit into
mainfrom
2026-04-24-fix-arithmetic-parameter-parsing-issue
Apr 25, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-04-24-fix-arithmetic-parameter-parsing-issue

Conversation

@chaliy

@chaliy chaliy commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • A naive search for "%%"/"##" inside expand_param_op_in_arithmetic could match those sequences inside the pattern portion (e.g. ${var%foo%%bar}), which truncated the variable name and produced incorrect arithmetic results.
  • The regression affects arithmetic-base expansions like 10#${var%foo%%bar} and 10#${var#foo##bar} and was introduced when adding operator handling for arithmetic contexts.
  • The goal is to detect the operator at the first operator boundary (left-to-right) so patterns containing %%/## are not misinterpreted as the operator location.

Description

  • Replace the global find-based detection in expand_param_op_in_arithmetic with a left-to-right char_indices() scan that identifies the first operator boundary and then dispatches handling for %%/%/##/# and :- accordingly in crates/bashkit/src/interpreter/mod.rs.
  • Add regression unit tests exercising ${var%foo%%bar} and ${var#foo##bar} inside arithmetic base expressions in mod tests of crates/bashkit/src/interpreter/mod.rs.
  • Extend spec coverage by adding matching spec cases to crates/bashkit/tests/spec_cases/bash/arithmetic-base-expansion.test.sh to ensure the behavior remains covered by the spec runner.

Testing

  • Ran cargo fmt --check which succeeded.
  • Ran targeted unit tests with cargo test --features http_client for the new tests and arithmetic_base scenarios, and the added tests test_arithmetic_base_suffix_pattern_with_double_percent and test_arithmetic_base_prefix_pattern_with_double_hash passed.
  • Ran the arithmetic_base test grouping and observed no regressions in existing arithmetic base tests (all executed tests passed).

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 24, 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 5e13c8b Commit Preview URL Apr 25 2026, 04:10 AM

@chaliy
chaliy force-pushed the 2026-04-24-fix-arithmetic-parameter-parsing-issue branch from 9436e4d to 5e13c8b Compare April 25, 2026 04:09
@chaliy
chaliy merged commit 12aa1bf into main Apr 25, 2026
34 checks passed
@chaliy
chaliy deleted the 2026-04-24-fix-arithmetic-parameter-parsing-issue branch April 25, 2026 04:19
@codecov

codecov Bot commented Apr 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

chaliy added a commit that referenced this pull request May 30, 2026
…tor (#1472)

### Motivation
- A naive search for `"%%"`/`"##"` inside
`expand_param_op_in_arithmetic` could match those sequences inside the
pattern portion (e.g. `${var%foo%%bar}`), which truncated the variable
name and produced incorrect arithmetic results.
- The regression affects arithmetic-base expansions like
`10#${var%foo%%bar}` and `10#${var#foo##bar}` and was introduced when
adding operator handling for arithmetic contexts.
- The goal is to detect the operator at the first operator boundary
(left-to-right) so patterns containing `%%`/`##` are not misinterpreted
as the operator location.

### Description
- Replace the global `find`-based detection in
`expand_param_op_in_arithmetic` with a left-to-right `char_indices()`
scan that identifies the first operator boundary and then dispatches
handling for `%%`/`%`/`##`/`#` and `:-` accordingly in
`crates/bashkit/src/interpreter/mod.rs`.
- Add regression unit tests exercising `${var%foo%%bar}` and
`${var#foo##bar}` inside arithmetic base expressions in `mod tests` of
`crates/bashkit/src/interpreter/mod.rs`.
- Extend spec coverage by adding matching spec cases to
`crates/bashkit/tests/spec_cases/bash/arithmetic-base-expansion.test.sh`
to ensure the behavior remains covered by the spec runner.

### Testing
- Ran `cargo fmt --check` which succeeded. 
- Ran targeted unit tests with `cargo test --features http_client` for
the new tests and `arithmetic_base` scenarios, and the added tests
`test_arithmetic_base_suffix_pattern_with_double_percent` and
`test_arithmetic_base_prefix_pattern_with_double_hash` passed.
- Ran the `arithmetic_base` test grouping and observed no regressions in
existing arithmetic base tests (all executed tests passed).

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_69eadf19cfa4832ba2ad750974669892)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant