Fix freply crash on unmatched braces - #3452
Open
lorenzo132 wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the bot’s SafeFormatter to avoid crashing when user-provided format strings (notably freply) contain malformed/unmatched braces, by falling back to formatting only complete {field} occurrences instead of rejecting the entire message.
Changes:
- Added a
SafeFormatter.format()override that catches certain brace-relatedValueErrors fromstring.Formatter. - Implemented a regex-based fallback that formats complete replacement fields individually and leaves malformed parts untouched.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: lorenzo132 <50767078+lorenzo132@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
core/models.py:373
- The fallback path depends on exact ValueError message strings to decide whether to recover, which is brittle across Python versions. Additionally, the per-field formatter currently swallows any ValueError and returns the raw placeholder, which can silently hide real formatting errors (e.g., invalid format specs) whenever the message contains an unrelated unmatched brace.
Consider always attempting the safe per-field fallback on ValueError, but only suppressing ValueErrors that are truly brace-related; re-raise other ValueErrors so formatting errors aren’t silently ignored.
def format(self, format_string, /, *args, **kwargs):
try:
return super().format(format_string, *args, **kwargs)
except ValueError as exc:
if str(exc) not in self._UNMATCHED_BRACE_ERRORS:
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.
No description provided.