Skip to content

Commit

Permalink
Revert "Update parsetree.py removed "?" from for x in re.compile(r"(\…
Browse files Browse the repository at this point in the history
…${.+})" …"

This reverts part of commit 042a63f.

Reverted the fix for 🎫`400` as it caused new issues when traversing
some bracketed situations.

Fixes: #401
Change-Id: I6310c4cc91bfce2852a91a7b5db88eb652ae9e38
  • Loading branch information
zzzeek committed May 14, 2024
1 parent c9c0534 commit dcc211c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
7 changes: 5 additions & 2 deletions doc/build/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions doc/build/unreleased/400.rst
Original file line number Diff line number Diff line change
@@ -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.

4 changes: 2 additions & 2 deletions mako/parsetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions test/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)}
Expand Down

0 comments on commit dcc211c

Please sign in to comment.