Skip to content

Commit

Permalink
Merge pull request #637 from pbu88/urlize_keep_ws_chars
Browse files Browse the repository at this point in the history
Makes urlize conserve any white space char

* pbu88/urlize_keep_ws_chars:
  Makes urlize conserve any white space char
  • Loading branch information
carljm committed Jan 19, 2016
2 parents 13abcba + efdd638 commit f715387
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ Changelog
master (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).

Expand Down
1 change: 1 addition & 0 deletions docs/templating.md
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/filters.js
Expand Up @@ -512,7 +512,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;
Expand Down Expand Up @@ -540,7 +540,7 @@ var filters = {

});

return words.join(' ');
return words.join('');
},

wordcount: function(str) {
Expand Down
6 changes: 5 additions & 1 deletion tests/filters.js
Expand Up @@ -558,7 +558,7 @@
equal('{{ "http://jinja.pocoo.org/docs/templates/)" | urlize | safe }}',
'<a href="http://jinja.pocoo.org/docs/templates/">http://jinja.pocoo.org/docs/templates/</a>');
equal('{{ "http://jinja.pocoo.org/docs/templates/\n" | urlize | safe }}',
'<a href="http://jinja.pocoo.org/docs/templates/">http://jinja.pocoo.org/docs/templates/</a>');
'<a href="http://jinja.pocoo.org/docs/templates/">http://jinja.pocoo.org/docs/templates/</a>\n');
equal('{{ "http://jinja.pocoo.org/docs/templates/&gt;" | urlize | safe }}',
'<a href="http://jinja.pocoo.org/docs/templates/">http://jinja.pocoo.org/docs/templates/</a>');

Expand All @@ -577,6 +577,10 @@
//markup in the text
equal('{{ "<b>what up</b>" | urlize | safe }}', '<b>what up</b>');

//breaklines and tabs in the text
equal('{{ "what\nup" | urlize | safe }}', 'what\nup');
equal('{{ "what\tup" | urlize | safe }}', 'what\tup');

finish(done);
});

Expand Down

0 comments on commit f715387

Please sign in to comment.