Skip to content

Fix Unicode case folding in indexed fixed-string searches - #174

Merged
Shengyu Fu (shengyfu) merged 2 commits into
mainfrom
shengyfu-unicode-literal-matching
Oct 6, 2026
Merged

Shengyu Fu (shengyfu) merged 2 commits into
mainfrom
shengyfu-unicode-literal-matching

Conversation

@shengyfu

Copy link
Copy Markdown
Member

Summary

Fixes #173.

  • Plan case-insensitive fixed strings by escaping them and reusing the Unicode-aware regex planner, instead of requiring trigrams from Unicode-lowercased text that the ASCII-folded index may not contain.
  • Preserve the case-sensitive literal fast path and literal treatment of regex metacharacters. Local-index and server searches share the fix; no index-format change or rebuild is required.
  • Add planner and three-backend CLI regressions for accented letters, fullwidth letters, long s/Kelvin folds, short patterns, smart case, multiple patterns, literal metacharacters, and ASCII-only matching. Document conservative candidate selection.

Like regex searches, case-insensitive fixed strings now narrow using only safe literal runs. Patterns without safe trigrams scan all indexed candidates rather than losing Unicode matches.

Validation

The new core and CLI regressions failed before the fix by dropping CAFÉ for -F -i café, then passed afterward.

  • cargo test -p tgrep-core --lib query::tests --quiet — 37 passed
  • cargo test -p tgrep-core --test case_insensitive_roundtrip --quiet — 1 passed
  • cargo test -p tgrep-cli --test ripgrep_compat --quiet — 235 passed, including explicit scan/local-index/server parity
  • cargo clippy --workspace --benches --quiet -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

Copilot AI balanced review requested due to automatic review settings October 5, 2026 22:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes incorrect Unicode case-fold handling for case-insensitive fixed-string (-F -i) indexed searches by reusing the Unicode-aware regex planner on escaped literals, ensuring candidates aren’t incorrectly excluded while preserving existing fast paths.

Changes:

  • Route case-insensitive literal planning through the regex planner using regex_syntax::escape to keep Unicode-aware decomposition and conservative candidate selection.
  • Add core and CLI regressions covering accented/fullwidth letters, long-s/Kelvin folds, short patterns, multiple patterns, metacharacters, and backend parity.
  • Document the conservative behavior when no safe trigrams can be derived (scan all indexed candidates).
File Description
tgrep-core/​src/​query.rs Updates literal query planning for -i to escape and delegate to the regex planner; expands test coverage for Unicode case folds and candidate preservation.
tgrep-cli/​tests/​ripgrep_compat.rs Adds end-to-end CLI regression ensuring -F -i preserves Unicode case-fold matches consistently across backends.
README.md Documents the new conservative candidate selection behavior for case-insensitive fixed strings.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tgrep-core/src/query.rs Outdated
Copilot AI balanced review requested due to automatic review settings October 5, 2026 22:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation is conservative, preserves literal semantics, and has comprehensive backend regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@shengyfu
Shengyu Fu (shengyfu) merged commit e9d55db into main Oct 6, 2026
12 checks passed
@shengyfu
Shengyu Fu (shengyfu) deleted the shengyfu-unicode-literal-matching branch October 6, 2026 02:37
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.

-F -i misses files whose matches differ by a non-ASCII case fold when an index is used (CAFÉ, fullwidth ID, ſ/K)

3 participants