diff --git a/src/textual/markup.py b/src/textual/markup.py index 60abb9f5cb..b78440855a 100644 --- a/src/textual/markup.py +++ b/src/textual/markup.py @@ -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. diff --git a/tests/test_escape_fix.py b/tests/test_escape_fix.py new file mode 100644 index 0000000000..c8c3cd01a2 --- /dev/null +++ b/tests/test_escape_fix.py @@ -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