Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes urlize conserve any white space char #637

Merged
merged 1 commit into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions docs/templating.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -520,7 +520,7 @@ var filters = {

});

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

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

Expand All @@ -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);
});

Expand Down