Skip to content

Commit

Permalink
Makes urlize conserve any white space char
Browse files Browse the repository at this point in the history
Paulo Bu committed Jan 18, 2016

Verified

This commit was signed with the committer’s verified signature.
1 parent b45db7a commit efdd638
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ Changelog
master (unreleased)
-------------------

* Fix a bug in urlize that would remove line break, tabs and any other
"white spacey" char different than white space.
* Don't suppress errors inside {% if %} tags. Thanks Artemy Tregubenko for
report and test, Ouyang Yadong for fix. Merge of
[#634](https://github.com/mozilla/nunjucks/pull/634).
1 change: 1 addition & 0 deletions docs/templating.md
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions src/filters.js
Original file line number Diff line number Diff line change
@@ -492,7 +492,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;
@@ -520,7 +520,7 @@ var filters = {

});

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

wordcount: function(str) {
6 changes: 5 additions & 1 deletion tests/filters.js
Original file line number Diff line number Diff line change
@@ -537,7 +537,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>');

@@ -556,6 +556,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);
});

0 comments on commit efdd638

Please sign in to comment.