Skip to content

Commit e5ca5a9

Browse files
committed
Address copilot nits
1 parent e3d3186 commit e5ca5a9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/guardrails/checks/text/keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def _compile_pattern(keywords: tuple[str, ...]) -> re.Pattern[str]:
7979
for keyword in keywords:
8080
escaped = re.escape(keyword)
8181
# Check first and last character of the original keyword for word character status
82-
starts_with_word_char = keyword and keyword[0].isalnum() or (keyword and keyword[0] == "_")
83-
ends_with_word_char = keyword and keyword[-1].isalnum() or (keyword and keyword[-1] == "_")
82+
starts_with_word_char = keyword and (keyword[0].isalnum() or keyword[0] == "_")
83+
ends_with_word_char = keyword and (keyword[-1].isalnum() or keyword[-1] == "_")
8484

8585
prefix = r"(?<!\w)" if starts_with_word_char else ""
8686
suffix = r"(?!\w)" if ends_with_word_char else ""

tests/unit/checks/test_keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ def test_match_keywords_mixed_punctuation_and_word_chars() -> None:
191191
result = match_keywords("test@user@test", config, guardrail_name="Test Guardrail")
192192
assert result.tripwire_triggered is True # noqa: S101
193193

194-
# Should not match when word chars continue into the keyword
194+
# Should match even when followed by more text (no boundaries applied to punctuation edges)
195195
result = match_keywords("test@user@more", config, guardrail_name="Test Guardrail")
196196
assert result.tripwire_triggered is True # noqa: S101

0 commit comments

Comments
 (0)