fix(config): guard SessionKey.from_safe_name against separator collision#3178
Open
nankingjing wants to merge 1 commit into
Open
fix(config): guard SessionKey.from_safe_name against separator collision#3178nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
SessionKey.from_safe_name used safe_name.split('__') without a maxsplit.
When a field value (typically chat_id, e.g. a feishu topic id or a Discord
thread id like 'thread__42') contained the '__' separator itself, the
round trip through safe_name() -> from_safe_name() silently truncated the
value: the part before the first inner '__' inflated channel_id and the
rest overwrote chat_id — or, when the result had exactly 3 parts, the
construction succeeded with corrupt fields.
Use split('__', maxsplit=2) so chat_id captures everything after the
second separator verbatim, and raise ValueError when the input has fewer
than 3 parts (i.e. not even a type/channel_id pair is present).
Regression test in tests/unit/test_config/test_session_key.py covers:
- basic round trip
- chat_id with one '__' (regression: was truncated before fix)
- chat_id with multiple '__' substrings
- too-few parts -> ValueError
- empty input -> ValueError
Contributor
Author
| Self-reviewed: diff is correct, minimal, and well-tested. No issues found. |
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.
Bug fix for SessionKey.from_safe_name: split('__') without maxsplit truncates chat_id when it contains the separator. Use maxsplit=2 and raise ValueError on too-few parts. 6 regression tests in tests/unit/test_config/test_session_key.py.