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

ExactTextMatching reports a match for an empty or whitespace-only target

Abierto Apto para principiantes
#2,881 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
91/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
security, testing

Línea de trabajo

Empieza en pyrit/analytics/text_matching.py, en ExactTextMatching.is_match(), y compara después la cobertura existente de test_target_too_short en tests/unit/analytics/test_text_matching.py. Añade cobertura para targets vacíos y compuestos únicamente por espacios en blanco, conservando el matching para targets no vacíos, y ejecuta las pruebas de text-matching enfocadas. Se considera terminado cuando los targets vacíos ya no hagan match y el comportamiento existente siga intacto.

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

Descripción

Describe the bug

ExactTextMatching.is_match() guards an empty text (if not text: return False) but not an empty target, and "" in anything is True in Python. With the default ignore_whitespace=True the check is reachable with a whitespace-only target too, because target.strip() turns it into "".

Its sibling in the same module, ApproximateTextMatching, has the opposite behaviour and says why:

if len(target) < self._n:
    return 0.0  # Confidence is too low for short targets

That rule is pinned by tests/unit/analytics/test_text_matching.py::test_target_too_short. So the two implementations of the same TextMatching interface disagree on a degenerate target.

This matters beyond the helper: DecodingScorer defaults to ExactTextMatching(case_sensitive=False) and calls it with no guard on user_piece.original_value and user_piece.converted_value — while guarding the adjacent decoded_text on the very next lines with if decoded_text and .... MessagePiece.converted_value defaults to "", so when no converter ran, the converted_value check matches every response and the scorer reports a successful decoding.

Steps/Code to Reproduce
from pyrit.analytics import ApproximateTextMatching, ExactTextMatching

print(ExactTextMatching().is_match(target="", text="I refuse to help with that."))
print(ExactTextMatching().is_match(target="   \n ", text="I refuse to help with that."))
print(ExactTextMatching(case_sensitive=True).is_match(target="", text="anything"))
print(ExactTextMatching(ignore_whitespace=False).is_match(target="", text="hello"))
print(ApproximateTextMatching().is_match(target="", text="hello world"))  # sibling
Expected Results

The first four should be False: a target that carries no content cannot be found in the text. The sibling already returns False. is_match(target="refuse", text="I refuse to help") should stay True.

Actual Results
True
True
True
True
False
Screenshots

Not applicable.

Versions
  • OS: macOS
  • Python version: 3.11
  • PyRIT version: installed from main in editable mode (pyrit/analytics/text_matching.py)
  • Existing coverage: tests/unit/analytics/test_text_matching.py::test_empty_text covers an empty text only; no test covers an empty target.
Proposed direction

I would add the symmetric guard to ExactTextMatching.is_match — return False when the (whitespace-normalised) target is empty — and a test mirroring test_target_too_short. That keeps the fix in the shared abstraction, so DecodingScorer and any other caller are covered without touching them. Happy to send a PR if that matches your intent; I am also happy to guard the two call sites in DecodingScorer instead if you prefer the narrower change.

Lenguaje dominante
Python
Estrellas
4.5k
Forks
896
Merge medio
3 d 2 h
PR fusionados (30 d)
210

Preparar el entorno

Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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/PyRIT

Todos los issues de microsoft/PyRIT

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.