Skip to content
Myr

Merge pull request #1366 from mvolfik/fix-unicode-newlines

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix unicode newlines

authored by David Lord · committed by GitHub · parents 59de6fb, 9dae67b · Browse files · 3 files+19 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+19 added−5 removed

  • tests:+7 added−0 removed
  • other:+12 added−5 removed

3 files+19 added−5 removed

modified:src/jinja2/lexer.py+10 added-5 removed
636 unmodified lines
637 yield Token(lineno, token, value)638639 def tokeniter(self, source, name, filename=None, state=None):640 """This method tokenizes the text and returns the tokens in a641 generator. Use this method if you just want to tokenize a template.641 generator. Use this method if you just want to tokenize a template.642643 .. versionchanged:: 3.0644 Only ``\\n``, ``\\r\\n`` and ``\\r`` are treated as line645 breaks.646 """643 lines = source.splitlines()644 if self.keep_trailing_newline and source:645 if source.endswith(("\r\n", "\r", "\n")):646 lines.append("")647 lines = newline_re.split(source)[::2]648649 if not self.keep_trailing_newline and lines[-1] == "":650 del lines[-1]651652 source = "\n".join(lines)653 pos = 0654 lineno = 1655 stack = ["root"]
166 unmodified lines
modified:tests/test_regression.py+7 added
743 unmodified lines
744 assert tmpl.render() == "bar y"745746 tmpl = env.get_template("base")747 assert tmpl.render() == "42 y"748749750@pytest.mark.parametrize("unicode_char", ["\N{FORM FEED}", "\x85"])751def test_unicode_whitespace(env, unicode_char):752 content = "Lorem ipsum\n" + unicode_char + "\nMore text"753 tmpl = env.from_string(content)754 assert tmpl.render() == content
modified:CHANGES.rst+2 added
54 unmodified lines
55- ``Undefined.__contains__`` (``in``) raises an ``UndefinedError``56 instead of a ``TypeError``. :issue:`1198`57- ``Undefined`` is iterable in an async environment. :issue:`1294`58- ``NativeEnvironment`` supports async mode. :issue:`1362`59- Template rendering only treats ``\n``, ``\r\n`` and ``\r`` as line60 breaks. Other characters are left unchanged. :issue:`769, 952, 1313`616263Version 2.11.364--------------
780 unmodified lines