From dcc211cf3abc96d35ad340c9f47347ac8a40b697 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 14 May 2024 08:02:28 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"Update=20parsetree.py=20removed=20"?= =?UTF-8?q?=3F"=20from=20for=20x=20in=20re.compile(r"(\${.+})"=20=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts part of commit 042a63f9d375812d46de758242d75c30e640b4e1. Reverted the fix for :ticket:`400` as it caused new issues when traversing some bracketed situations. Fixes: #401 Change-Id: I6310c4cc91bfce2852a91a7b5db88eb652ae9e38 --- doc/build/changelog.rst | 7 +++++-- doc/build/unreleased/400.rst | 7 +++++++ mako/parsetree.py | 4 ++-- test/test_lexer.py | 23 +++++++++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 doc/build/unreleased/400.rst diff --git a/doc/build/changelog.rst b/doc/build/changelog.rst index 23d362a9..bf954f21 100644 --- a/doc/build/changelog.rst +++ b/doc/build/changelog.rst @@ -11,11 +11,11 @@ Changelog :include_notes_from: unreleased .. changelog:: - :version: 1.3.4 + :version: 1.3.4 (yanked) :released: Mon May 13 2024 .. change:: - :tags: bug, parser + :tags: bug, lexer :tickets: 398 Fixed regression caused by the fix for :ticket:`320` where new logic added @@ -31,6 +31,9 @@ Changelog dictionary literals, would fail to be interpreted correctly even though the initial parsing is correct. Pull request courtesy Jose Galvez. + .. note:: this change was **reverted** and release 1.3.4 was yanked as + this fix caused regressions. + .. changelog:: :version: 1.3.3 :released: Wed Apr 10 2024 diff --git a/doc/build/unreleased/400.rst b/doc/build/unreleased/400.rst new file mode 100644 index 00000000..2c98fdf4 --- /dev/null +++ b/doc/build/unreleased/400.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, lexer, regression + :tickets: 400, 401 + + Reverted the fix for :ticket:`400` as it caused new issues when traversing + some bracketed situations. + diff --git a/mako/parsetree.py b/mako/parsetree.py index dae707c1..04686ece 100644 --- a/mako/parsetree.py +++ b/mako/parsetree.py @@ -322,10 +322,10 @@ def _parse_attributes(self, expressions, nonexpressions): for key in self.attributes: if key in expressions: expr = [] - for x in re.compile(r"(\${.+})", re.S).split( + for x in re.compile(r"(\${.+?})", re.S).split( self.attributes[key] ): - m = re.compile(r"^\${(.+)}$", re.S).match(x) + m = re.compile(r"^\${(.+?)}$", re.S).match(x) if m: code = ast.PythonCode( m.group(1).rstrip(), **self.exception_kwargs diff --git a/test/test_lexer.py b/test/test_lexer.py index b1a796cd..d8029a17 100644 --- a/test/test_lexer.py +++ b/test/test_lexer.py @@ -810,7 +810,25 @@ def test_tricky_expression(self): ), ) - def test_dict_expression(self): + def test_dict_expression_issue_400_regression(self): + """test for issue #401. + + This was the regression case for #400 + + """ + template = '<%include file="${foo}${bar}"/>' + + nodes = Lexer(template).parse() + self._compare( + nodes, + TemplateNode( + {}, + [IncludeTag("include", {"file": "${foo}${bar}"}, (1, 1), [])], + ), + ) + + def _dont_test_dict_expression_issue_400(self): + """test for issue #400""" template = """ <%def name="dtest(d)"> % for k,v in d.items(): @@ -868,7 +886,8 @@ def test_dict_expression(self): ), ) - def test_dict_expression_2(self): + def _dont_test_dict_expression_2_issue_400(self): + """test for issue #400""" template = """ <%def name="thing(thing)"> ${type(thing)}