diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e8560b..d946d5d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Changelog 2.x (unreleased) ---------------- +* Fix a bug in urlize that collapsed whitespace. Thanks Paulo Bu. Merge of + [#637](https://github.com/mozilla/nunjucks/pull/637). + * Add `sum` filter. Thanks Pablo Matías Lazo. Merge of [#629](https://github.com/mozilla/nunjucks/pull/629). diff --git a/docs/templating.md b/docs/templating.md index 692cd4d4..c3ac0e10 100644 --- a/docs/templating.md +++ b/docs/templating.md @@ -822,6 +822,7 @@ linebreaks. Use second behavior if you want to pipe * [truncate](http://jinja.pocoo.org/docs/templates/#truncate) * [upper](http://jinja.pocoo.org/docs/templates/#upper) * [urlencode](http://jinja.pocoo.org/docs/templates/#urlencode) +* [urlize](http://jinja.pocoo.org/docs/templates/#urlize) * [wordcount](http://jinja.pocoo.org/docs/templates/#wordcount) * [float](http://jinja.pocoo.org/docs/templates/#float) * [int](http://jinja.pocoo.org/docs/templates/#int) diff --git a/src/filters.js b/src/filters.js index 45a0004b..650c7ee2 100644 --- a/src/filters.js +++ b/src/filters.js @@ -513,7 +513,7 @@ var filters = { var wwwRE = /^www\./; var tldRE = /\.(?:org|net|com)(?:\:|\/|$)/; - var words = str.split(/\s+/).filter(function(word) { + var words = str.split(/(\s+)/).filter(function(word) { // If the word has no length, bail. This can happen for str with // trailing whitespace. return word && word.length; @@ -541,7 +541,7 @@ var filters = { }); - return words.join(' '); + return words.join(''); }, wordcount: function(str) { diff --git a/tests/filters.js b/tests/filters.js index 6510a987..b50b65e7 100644 --- a/tests/filters.js +++ b/tests/filters.js @@ -552,7 +552,7 @@ equal('{{ "http://jinja.pocoo.org/docs/templates/)" | urlize | safe }}', 'http://jinja.pocoo.org/docs/templates/'); equal('{{ "http://jinja.pocoo.org/docs/templates/\n" | urlize | safe }}', - 'http://jinja.pocoo.org/docs/templates/'); + 'http://jinja.pocoo.org/docs/templates/\n'); equal('{{ "http://jinja.pocoo.org/docs/templates/>" | urlize | safe }}', 'http://jinja.pocoo.org/docs/templates/'); @@ -571,6 +571,10 @@ //markup in the text equal('{{ "what up" | urlize | safe }}', 'what up'); + //breaklines and tabs in the text + equal('{{ "what\nup" | urlize | safe }}', 'what\nup'); + equal('{{ "what\tup" | urlize | safe }}', 'what\tup'); + finish(done); });