From: Mark Amery Date: Sun, 25 Nov 2018 17:49:22 +0000 (+0000) Subject: Fix broken nl2br filter example X-Git-Tag: 2.11.0~102^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e410c7b04a91cb296aaaa39788d67bf8491b986;p=thirdparty%2Fjinja.git Fix broken nl2br filter example This example attempts to handle both Windows-style and Unix-style line endings, but does it wrong; as noted at https://stackoverflow.com/q/12521127/1709587, the regex here will match a single \r\n as if it were a double line-break, which results in all single Windows-style line-breaks getting converted into

breaks instead of
breaks as intended. This patch fixes that by applying Alan Moore's proposed fix from https://stackoverflow.com/a/12521544/1709587 of using a negative lookahead so that a \r cannot be counted as a line break if it is followed by a \n (while still allowing the \r\n combination to count as a line break). --- diff --git a/docs/api.rst b/docs/api.rst index 6db7507f..47760e36 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -740,7 +740,7 @@ enabled:: import re from jinja2 import evalcontextfilter, Markup, escape - _paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}') + _paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}') @evalcontextfilter def nl2br(eval_ctx, value):