Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`-S/--smart-case` ignores `-e`/`-f` patterns and counts escapes like `\S` as uppercase

Cerrado
#183 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #187 de @shengyfu — fusionado

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
57/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
cli, search

Línea de trabajo

Start with SearchOptions::effective_case_insensitive in tgrep-cli/src/search.rs, then trace how all_patterns() and parsed patterns feed the query plan and matcher. Read the existing search tests and add regression coverage for the four reproductions, including escaped uppercase characters and -e/-f; done when smart-case behavior matches the stated ripgrep expectations in indexed and no-index searches.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

-S/--smart-case decides case sensitivity in a way that differs from ripgrep in two cases:

  1. It only looks at the positional pattern. With -e or -f the positional pattern is empty, so the search is always case-insensitive, even when the given patterns contain uppercase letters.
  2. It treats every uppercase character in the pattern text as uppercase, including those in escapes such as \S, \W or \D. ripgrep only counts uppercase literals: "of the literals in the pattern, none of them are considered to be uppercase according to Unicode. For example, foo\pL has no uppercase literals but Foo\pL does."

The first returns extra matches. The second misses matches. Both happen with and without the index.

Reproduce

mkdir repro && cd repro
mkdir d
printf 'abc\n' > d/lower.txt
printf 'ABC\n' > d/upper.txt
printf 'ABC\n' > pats.txt          # outside d/ so the pattern file itself is not searched

tgrep --no-index -S -e ABC d
tgrep --no-index -S -f pats.txt d
tgrep --no-index -S -e abc -e XYZ d
tgrep --no-index -S 'a\Sc' d
Query Actual: tgrep Expected: rg 15.1.0
-S -e ABC d upper.txt, lower.txt upper.txt
-S -f pats.txt d (contains ABC) upper.txt, lower.txt upper.txt
-S -e abc -e XYZ d upper.txt, lower.txt lower.txt
-S 'a\Sc' d lower.txt upper.txt, lower.txt

ripgrep applies smart case to the patterns as a whole: if any pattern has an uppercase literal, the search is case-sensitive, which is why -e abc -e XYZ does not match ABC.

Environment

  • tgrep 1.1.0, built from 1120aca (current main) with rustc 1.95.0 (59807616e 2026-04-14)
  • Windows 11 Pro (build 28000); the code involved is platform-independent
  • Same results with --no-index and with a local index; -S -e ABC also reproduces through tgrep serve

Cause

SearchOptions::effective_case_insensitive checks only self.pattern, using char::is_uppercase on the raw text:

https://github.com/microsoft/tgrep/blob/1120aca41dd192ae61bdd996e9886cb354a78a27/tgrep-cli/src/search.rs#L235-L237

When -e or -f is used, the positional argument moves to the path list and self.pattern is empty (search.rs#L432-L439), so the check is always true. The result feeds both the query plan and the matcher (search.rs#L817) and is sent to the server, so indexed searches get the same wrong case mode as scans.

Possible fix

Compute smart case from all_patterns() instead of self.pattern, with the search case-sensitive if any pattern has an uppercase literal:

  • With -F, every character is a literal, so is_uppercase on the raw text is correct.
  • Otherwise, parse each pattern with regex_syntax::ast and look only at literal characters, as ripgrep's grep-regex does. A pattern with no literals at all (\w+) is not "all lowercase" under ripgrep's rule, so it stays case-sensitive.

A regression test could cover the four queries above.

Lenguaje dominante
Rust
Estrellas
3.4k
Forks
138
Merge medio
13 h 24 min
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/tgrep

Todos los issues de microsoft/tgrep

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.