fix(gateway): repair and optimize lookahead bracket class in MEDIA regex - #29620
Closed
InphinitiZ wants to merge 1 commit into
Closed
fix(gateway): repair and optimize lookahead bracket class in MEDIA regex#29620InphinitiZ wants to merge 1 commit into
InphinitiZ wants to merge 1 commit into
Conversation
- Relocate ']' to the beginning of the character class in Lookahead assertion so that Python's regex compiler properly includes it as a member of the class instead of prematurely closing the character class. - Add '}' into the lookahead set. - Ensure correct matching and parsing of MEDIA: tags wrapped in brackets, braces or backslashes on all gateway platforms.
This was referenced May 26, 2026
Contributor
|
This looks implemented on current main via the later consolidated MEDIA extraction work. Automated hermes-sweeper review evidence:
Thanks for surfacing this; it helped identify the MEDIA regex cluster that was fixed on main. |
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
There is a critical escaping issue in the
MEDIA:regex lookahead character class ingateway/platforms/base.py:Inside a raw Python string,
\\\]resolves to\\\]which represents an escaped backslash\\\\and then a raw closing bracket]. This prematurely closes the character class compilation, rendering any subsequent characters (like}or a second]) completely outside the character class. As a result, paths inside parens or brackets likeMEDIA:/tmp/test.png)would fail to extract correctly on the gateway.Fix
Relocate the closing bracket
](and trailing curly brace}) to the very beginning of the character class directly after[:This is the standard and safest regex practice for including closing brackets inside character classes without triggering compile-time escapes or premature closures. All unit tests pass locally.