diff --git a/mako/lexer.py b/mako/lexer.py index 953c0a0..527c4b5 100644 --- a/mako/lexer.py +++ b/mako/lexer.py @@ -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, ) diff --git a/test/test_template.py b/test/test_template.py index f2ca6b4..a616fae 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -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