Skip to content

fix(gateway): repair and optimize lookahead bracket class in MEDIA regex - #29620

Closed
InphinitiZ wants to merge 1 commit into
NousResearch:mainfrom
InphinitiZ:fix/media-ignorecase-and-backslash-escape-pr
Closed

fix(gateway): repair and optimize lookahead bracket class in MEDIA regex#29620
InphinitiZ wants to merge 1 commit into
NousResearch:mainfrom
InphinitiZ:fix/media-ignorecase-and-backslash-escape-pr

Conversation

@InphinitiZ

@InphinitiZ InphinitiZ commented May 21, 2026

Copy link
Copy Markdown

Summary

There is a critical escaping issue in the MEDIA: regex lookahead character class in gateway/platforms/base.py:

(?=[\\s`"',;:)\\\\\\]}]|$)

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 like MEDIA:/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 [:

(?=[]}\\s`"',;:)\\\\]|$)

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.

- 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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels May 21, 2026
@teknium1

Copy link
Copy Markdown
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.

@teknium1 teknium1 closed this Jun 20, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants