]> git.ipfire.org Git - thirdparty/jinja.git/commit
Fix broken nl2br filter example 929/head
authorMark Amery <markamery@btinternet.com>
Sun, 25 Nov 2018 17:49:22 +0000 (17:49 +0000)
committerMark Amery <markamery@btinternet.com>
Sun, 25 Nov 2018 17:49:22 +0000 (17:49 +0000)
commit9e410c7b04a91cb296aaaa39788d67bf8491b986
tree89fde08bf59156d15f8b558bc1a7b9be1e97f105
parenta7f1f528f5e77d5401a96aa326885508245f7c6f
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 <p> breaks instead of <br> 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).
docs/api.rst