From 1c1018fa77c62e39aed8d1eb08d99d31a31831aa Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Mon, 21 Aug 2023 12:01:15 -0500 Subject: [PATCH] Backport PR #26519: Fix mathtext mismatched braces --- lib/matplotlib/_mathtext.py | 7 ++++++- lib/matplotlib/tests/test_mathtext.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 324ba2af7a5f..5b4e8ed20db3 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -1936,6 +1936,7 @@ def csnames(group, names): p.function = csnames("name", self._function_names) p.group = p.start_group + ZeroOrMore(p.token)("group") + p.end_group + p.unclosed_group = (p.start_group + ZeroOrMore(p.token)("group") + StringEnd()) p.frac = cmd(r"\frac", p.required_group("num") + p.required_group("den")) p.dfrac = cmd(r"\dfrac", p.required_group("num") + p.required_group("den")) @@ -1984,6 +1985,7 @@ def csnames(group, names): p.token <<= ( p.simple | p.auto_delim + | p.unclosed_group | p.unknown_symbol # Must be last ) @@ -2072,7 +2074,7 @@ def main(self, s, loc, toks): return [Hlist(toks)] def math_string(self, s, loc, toks): - return self._math_expression.parseString(toks[0][1:-1]) + return self._math_expression.parseString(toks[0][1:-1], parseAll=True) def math(self, s, loc, toks): hlist = Hlist(toks) @@ -2294,6 +2296,9 @@ def end_group(self, s, loc, toks): self.pop_state() return [] + def unclosed_group(self, s, loc, toks): + raise ParseFatalException(s, len(s), "Expected '}'") + def font(self, s, loc, toks): self.get_state().font = toks["font"] return [] diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index d80312495d91..5a9e8a8b9264 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -320,6 +320,7 @@ def test_fontinfo(): (r'$a^2^2$', r'Double superscript'), (r'$a_2_2$', r'Double subscript'), (r'$a^2_a^2$', r'Double superscript'), + (r'$a = {b$', r"Expected '}'"), ], ids=[ 'hspace without value', @@ -347,7 +348,8 @@ def test_fontinfo(): 'unknown symbol', 'double superscript', 'double subscript', - 'super on sub without braces' + 'super on sub without braces', + 'unclosed group', ] ) def test_mathtext_exceptions(math, msg): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy