Skip to content

Commit

Permalink
dont consume ampersands
Browse files Browse the repository at this point in the history
Fixed long standing bug where the sequence ``<&`` would be misinterpreted
by the lexer.   It's not clear why the ampersand character was part of the
characters being consumed here and it may have been an inadvertent bit of
code from one of Mako's predecessor languages.

Fixes: #412
Change-Id: I41ba50da919a6c8b3557bdd2313aa545b51b2b9b
  • Loading branch information
zzzeek committed Oct 21, 2024
1 parent 6b5fb32 commit 0348fe3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doc/build/unreleased/412.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. change::
:tags: bug, lexer
:tickets: 412

Fixed long standing bug where the sequence ``<&`` would be misinterpreted
by the lexer. It's not clear why the ampersand character was part of the
characters being consumed here and it may have been an inadvertent bit of
code from one of Mako's predecessor languages.
2 changes: 1 addition & 1 deletion mako/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def match_text(self):
|
(?=\${) # an expression
|
(?=</?[%&]) # a substitution or block or call start or end
(?=</?%) # a substitution or block or call start or end
# - don't consume
|
(\\\r?\n) # an escaped newline - throw away
Expand Down
11 changes: 11 additions & 0 deletions test/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ def test_dict_expression_issue_400_regression(self):
),
)

def test_ampersand_issue_412(self):
template = """
property = <&node>;
"""
nodes = Lexer(template).parse()
self._compare(
nodes,
TemplateNode({}, [Text("\nproperty = <&node>;\n\n", (1, 1))]),
)

def _dont_test_dict_expression_issue_400(self):
"""test for issue #400"""
template = """
Expand Down

0 comments on commit 0348fe3

Please sign in to comment.