Skip to content

fix(rg): escape glob class set operators - #1959

Merged
chaliy merged 1 commit into
mainfrom
2026-06-05-fix-rg-glob-class-regex-handling
Jun 5, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-06-05-fix-rg-glob-class-regex-handling

Conversation

@chaliy

@chaliy chaliy commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Rust regex treats tokens like &&, ~~, and -- specially inside character classes, which caused converted glob classes (e.g. [a&&b]) to be interpreted incorrectly.
  • This led to incorrect --glob, --type-add and ignore/type matching behavior compared to real ripgrep and allowed patterns that ripgrep rejects.
  • The change aims to preserve real-ripgrep semantics by escaping regex set-operator characters and preserving invalid-range rejection for double-hyphen sequences.

Description

  • Escape & and ~ when emitting glob character-class members by updating push_glob_class_char in crates/bashkit/src/builtins/rg/mod.rs.
  • Detect a -- sequence inside a class body in glob_class_to_regex and emit an escaped form to avoid Rust regex set-difference parsing so that invalid ranges remain rejected by the glob parser.
  • Add unit tests exercising [a&&b].txt, [a~~b].txt, and the invalid [a--b].txt cases to cover both glob and type parsing paths in the same file.

Testing

  • Ran cargo fmt --check which succeeded.
  • Ran the focused unit tests via cargo test -p bashkit glob_bracket_classes --no-default-features and both new tests passed.
  • Ran a local test build and unit-test run for the crate which completed with the new tests passing (no failures reported).

Codex Task

Copilot AI review requested due to automatic review settings June 5, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the rg glob-to-regex conversion so glob character classes preserve ripgrep semantics when compiled by Rust’s regex engine, specifically avoiding regex set-operator parsing inside [...] that would otherwise change matching behavior or accept patterns ripgrep rejects.

Changes:

  • Escape & and ~ when emitting glob character-class members to prevent Rust regex set-operator interpretation (&&, ~~).
  • Detect -- sequences inside class bodies and emit an escaped form to avoid Rust regex set-difference parsing while keeping [a--b] rejected.
  • Add unit tests covering &&, ~~, and invalid -- cases through both glob and type parsing paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 5, 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 53eedbd Commit Preview URL Jun 05 2026, 08:30 PM

@chaliy
chaliy merged commit 4885656 into main Jun 5, 2026
36 checks passed
@chaliy
chaliy deleted the 2026-06-05-fix-rg-glob-class-regex-handling branch June 5, 2026 20:56
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.

2 participants