Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matching multiline control lines in templates with CRLF line endings #346

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mako/lexer.py
Expand Up @@ -420,7 +420,7 @@ def match_expression(self):

def match_control_line(self):
match = self.match(
r"(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\r?\n)|[^\r\n])*)"
r"(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\\r?\n)|[^\r\n])*)"
r"(?:\r?\n|\Z)",
re.M,
)
Expand Down
20 changes: 20 additions & 0 deletions test/test_template.py
Expand Up @@ -32,6 +32,26 @@ def __exit__(self, *arg):
pass


class MiscTest(TemplateTest):
def test_crlf_linebreaks(self):

crlf = r"""
<%
foo = True
bar = True
%>
% if foo and \
bar:
foo and bar
%endif
"""
crlf = crlf.replace("\n", "\r\n")
self._do_test(
Template(crlf),
"\r\n\r\n foo and bar\r\n"
)


class EncodingTest(TemplateTest):
def test_escapes_html_tags(self):
from mako.exceptions import html_error_template
Expand Down