Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/textual/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class StyleTokenizer(TokenizerState):

def escape(
markup: str,
_escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@][^[]*?])").sub,
_escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@].*?])").sub,
) -> str:
"""Escapes text so that it won't be interpreted as markup.

Expand Down
9 changes: 9 additions & 0 deletions tests/test_escape_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

from textual.markup import escape, to_content

def test_escape_nested_brackets():
problematic_string = "[type=x, v={'a[0]'}]"
escaped = escape(problematic_string)
assert escaped == "\\[type=x, v={'a[0]'}]"
content = to_content(escaped)
assert str(content) == problematic_string