fix(text): command_body no longer crashes when bot_username is None - #25
Merged
Conversation
Line 49 unconditionally called re.escape(bot_username) before the None guard on line 50, so command_body raised TypeError whenever BOT_USERNAME was unset. That propagated through command_handlers. handle → router.handle_update → app.py's outer try/except, which silently logged the error, and users saw no response to any slash command. Bots deployed without BOT_USERNAME were effectively DOA for /start, /help, /remind, /list, /cancel, /timezone, /groupmode. Move the None check before pattern construction so re.escape only sees a real string. Add a test module (tests/test_text.py) that locks down both branches (bot_username=None accepts bare and "@anybot" suffixes; bot_username set accepts bare and matching suffix), plus baseline strip_bot_mention coverage that was missing. Generated with AI Co-Authored-By: AI <ai@example.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pre-existing bug 修正:
src/remindly/reminders/text.py:48-57的command_body在bot_username=None時直接 crash。Bug trace
Line 49 無條件呼叫
re.escape(bot_username)。若使用者部署未設BOT_USERNAME(settings.py允許 None),任何/start、/help、/remind、/list、/cancel、/timezone、/groupmode都會拋TypeError。影響鏈
/helpcommand_handlers.handle迭代呼叫command_bodyTypeError(handle 沒 try/except)router.handle_update(也沒 try/except)app.py主迴圈try/except Exception抓下並 log 一行修法(reorder)
先分支再構造 pattern,
re.escape只看到真的字串。Test plan
make test— 154 tests 全過(146 → 154,新增 8)make lint— ruff 全綠tests/test_text.py:test_matches_bare_command_when_bot_username_none(bare/remind)test_matches_at_suffix_command_when_bot_username_none(/remind@AnyBot)test_does_not_match_wrong_command_when_bot_username_nonetest_matches_at_suffix_command_when_bot_username_set(/remind@ReminderBot)test_bare_command_still_matches_when_bot_username_setstrip_bot_mention3 個 baseline case(原本沒 test)相關