Repository navigation
fix(rg): escape glob class set operators - #1959
Merged
Merged
Conversation
There was a problem hiding this comment.
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.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 53eedbd | Commit Preview URL | Jun 05 2026, 08:30 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
regextreats tokens like&&,~~, and--specially inside character classes, which caused converted glob classes (e.g.[a&&b]) to be interpreted incorrectly.--glob,--type-addand ignore/type matching behavior compared to real ripgrep and allowed patterns that ripgrep rejects.Description
&and~when emitting glob character-class members by updatingpush_glob_class_charincrates/bashkit/src/builtins/rg/mod.rs.--sequence inside a class body inglob_class_to_regexand emit an escaped form to avoid Rust regex set-difference parsing so that invalid ranges remain rejected by the glob parser.[a&&b].txt,[a~~b].txt, and the invalid[a--b].txtcases to cover both glob and type parsing paths in the same file.Testing
cargo fmt --checkwhich succeeded.cargo test -p bashkit glob_bracket_classes --no-default-featuresand both new tests passed.Codex Task