Skip to content

Commit 0348fe3

Browse files
committed
dont consume ampersands
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
1 parent 6b5fb32 commit 0348fe3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/build/unreleased/412.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. change::
2+
:tags: bug, lexer
3+
:tickets: 412
4+
5+
Fixed long standing bug where the sequence ``<&`` would be misinterpreted
6+
by the lexer. It's not clear why the ampersand character was part of the
7+
characters being consumed here and it may have been an inadvertent bit of
8+
code from one of Mako's predecessor languages.

mako/lexer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def match_text(self):
375375
|
376376
(?=\${) # an expression
377377
|
378-
(?=</?[%&]) # a substitution or block or call start or end
378+
(?=</?%) # a substitution or block or call start or end
379379
# - don't consume
380380
|
381381
(\\\r?\n) # an escaped newline - throw away

test/test_lexer.py

+11
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,17 @@ def test_dict_expression_issue_400_regression(self):
827827
),
828828
)
829829

830+
def test_ampersand_issue_412(self):
831+
template = """
832+
property = <&node>;
833+
834+
"""
835+
nodes = Lexer(template).parse()
836+
self._compare(
837+
nodes,
838+
TemplateNode({}, [Text("\nproperty = <&node>;\n\n", (1, 1))]),
839+
)
840+
830841
def _dont_test_dict_expression_issue_400(self):
831842
"""test for issue #400"""
832843
template = """

0 commit comments

Comments
 (0)