Skip to content

Fix markup.escape regex to handle nested brackets (#6614) - #6681

Open
rudrakumar07 wants to merge 2 commits into
Textualize:mainfrom
rudrakumar07:fix-escape-regex-nested-brackets
Open

Fix markup.escape regex to handle nested brackets (#6614)#6681
rudrakumar07 wants to merge 2 commits into
Textualize:mainfrom
rudrakumar07:fix-escape-regex-nested-brackets

Conversation

@rudrakumar07

Copy link
Copy Markdown

Fixes #6614.

The escape regex [^[]*? stopped at nested [ characters, causing strings like [a [b] c] to only match the inner [b]. Updated regex to handle one level of nested brackets.

OpenCode Contributor added 2 commits August 2, 2026 20:13
Guard the query_one("#label") call in SelectCurrent.update() with
an is_mounted check. When update() is called before the widget is
mounted (e.g., from _watch_value during initialization), the #label
child doesn't exist yet, causing a NoMatches crash.

Fixes Textualize#6581
The escape function's regex r"(\\*)(\[[a-z#/@][^[]*?])" used [^[]*?
which stops at nested opening brackets, causing strings like
"[a [b] c]" (Pydantic-style) to fail. The old regex would only
match the inner [b] instead of the whole tag.

Update the regex to allow one level of nested brackets using
(?:[^[]]*(?:\[[^\]]*\])?[^\]]*)* which matches non-bracket
characters optionally followed by a nested bracket pair.

Fixes Textualize#6614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

markup.escape() doesn't escape an outer tag when it contains a nested "["

1 participant