Skip to content

fix(permissions): glob_matches middle-wildcard matches commands with no trailing arguments#1200

Merged
FlorianBruniaux merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1105
Apr 13, 2026
Merged

fix(permissions): glob_matches middle-wildcard matches commands with no trailing arguments#1200
FlorianBruniaux merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1105

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Apr 10, 2026

Summary

  • glob_matches failed to match commands that terminated at the middle-wildcard token with no trailing arguments
  • Example: pattern git -C * diff:* matched git -C /path diff --stat (has trailing flag) but NOT bare git -C /path diff
  • Root cause: normalization turns git -C * diff:*git -C * diff *, splitting into ["git -C ", " diff ", ""]. Middle segment " diff " has a trailing space; /path diff ends with " diff" (no trailing space), so str::find(" diff ") returns None → the command is incorrectly rejected
  • Fix: in the middle-segment branch, also check remaining.ends_with(part.trim_end()) as fallback — this handles commands that end at the middle token with no trailing args

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets — no new errors
  • cargo test --all — all 1374 tests pass
  • New test: test_middle_wildcard_at_end_of_command — covers both positive cases (bare command, command with args) and a negative case

Closes #1105

🤖 Generated with Ora Studio

…ut trailing args (rtk-ai#1105)

When glob_matches processed a pattern like "git -C * diff:*" (normalized
to "git -C * diff *"), middle segment " diff " requires a trailing space
to match. For "git -C /path diff" the remaining text is "/path diff"
which ends with " diff" — no trailing space — so .find(" diff ") returned
None and the command was incorrectly rejected.

Fix: in the middle-segment branch, if the full substring search fails,
also check if the remaining text ends with the trimmed (right-stripped)
segment. This handles commands that terminate at the middle token with
no trailing arguments.

Add regression test covering the exact reproduction case from the issue.

Closes rtk-ai#1105

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@FlorianBruniaux FlorianBruniaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean fix, tests pass.

@FlorianBruniaux FlorianBruniaux merged commit 8126a20 into rtk-ai:develop Apr 13, 2026
10 checks passed
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