fix(python/robomp): updated mention regex to correctly reject suffixes

- Updated the mention extraction regex to prevent partial matching when a suffix follows the `[bot]` identifier.
- Added a regression test to ensure that invalid extended suffixes are correctly rejected.
This commit is contained in:
can1357
2026-06-21 19:26:42 +02:00
parent 24a0c8428a
commit 69d0ac4dd3
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ def extract_mention(body: str | None, bot_login: str) -> str | None:
if not login:
return None
pattern = re.compile(
rf"(?<![A-Za-z0-9_-])@{re.escape(login)}(?:\[bot\])?(?![A-Za-z0-9_-])",
rf"(?<![A-Za-z0-9_-])@{re.escape(login)}(?:\[bot\](?![A-Za-z0-9_-])|(?![A-Za-z0-9_\[-]))",
re.IGNORECASE,
)
if not pattern.search(body):
@@ -538,6 +538,10 @@ def test_extract_mention_strips_literal_app_suffix_from_body() -> None:
assert extract_mention("@roboomp[bot] go ahead", "roboomp[bot]") == "go ahead"
def test_extract_mention_rejects_extended_literal_app_suffix() -> None:
assert extract_mention("@roboomp[bot]-helper go ahead", "roboomp[bot]") is None
def test_extract_mention_returns_none_without_mention() -> None:
assert extract_mention("hello there", "robomp-bot") is None
assert extract_mention(None, "robomp-bot") is None