Skip to content

Fix: exact text matching empty target - #2882

Merged
Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
aspire488:fix/exact-text-matching-empty-target
Sep 28, 2026
Merged

Roman Lutz (romanlutz) merged 5 commits into
microsoft:mainfrom
aspire488:fix/exact-text-matching-empty-target

Conversation

@aspire488

@aspire488 Joel (aspire488) commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Tests and Documentation

Description

Fixes an edge case in "ExactTextMatching" where an empty or whitespace-only target could incorrectly produce a match.

Python treats an empty string as being contained in every string (""" in text"), so an empty target could result in a false positive. This is particularly relevant when matching values that may default to an empty string.

Changes

  • Reject empty targets in "ExactTextMatching.is_match()".
  • Normalize whitespace before checking whether the target is empty.
  • Add regression coverage for both empty and whitespace-only targets.

Related Issue

Closes #2881

Validation

Added unit tests covering:

  • "target="""
  • "target=" \n ""

Non-empty matching behavior remains unchanged.

Comment thread tests/unit/analytics/test_text_matching.py
Comment thread pyrit/analytics/text_matching.py Outdated
@romanlutz Roman Lutz (romanlutz) changed the title Fix/exact text matching empty target Fix: exact text matching empty target Sep 28, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Sep 28, 2026
Merged via the queue into microsoft:main with commit dff83aa Sep 28, 2026
49 checks passed
@aspire488

Copy link
Copy Markdown
Contributor Author

Thank you for reviewing and merging this! Really appreciate the thoughtful feedback throughout the process.

It’s been great contributing to PyRIT, and I’m looking forward to continuing to work on improvements and picking up more issues in the future.

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.

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

2 participants