Skip to content

Commit

Permalink
Fix infinite loop when calling an undefined function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom authored and carljm committed Sep 29, 2015
1 parent 5490fba commit b638d15
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
master (unreleased)
-------------------

* Fix error propagation. Thanks Tom Delmas. Merge of
[#534](https://github.com/mozilla/nunjucks/pull/534).


v2.1.0 (Sep 21 2015)
--------------------

Expand Down
8 changes: 6 additions & 2 deletions src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,12 @@ Template = Obj.extend({
context,
frame,
runtime,
function() {
cb(null, context.getExported());
function(err) {
if ( err ) {
cb(err, null);
} else {
cb(null, context.getExported());
}
});
},

Expand Down
29 changes: 29 additions & 0 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,5 +1125,34 @@
'may the forth be with you');
finish(done);
});

it('should throw an error when including a file that calls an undefined macro', function(done) {
render(
'{% include "undefined-macro.html" %}',
{},
{ noThrow: true },
function(err, res) {
expect(res).to.be(undefined);
expect(err).to.match(/Unable to call `\w+`, which is undefined or falsey/);
}
);

finish(done);
});

it('should throw an error when including a file that imports macro that calls an undefined macro', function(done) {
render(
'{% include "import-macro-call-undefined-macro.html" %}',
{ 'list' : [1, 2, 3] },
{ noThrow: true },
function(err, res) {
expect(res).to.be(undefined);
expect(err).to.match(/Unable to call `\w+`, which is undefined or falsey/);
}
);

finish(done);
});

});
})();
4 changes: 4 additions & 0 deletions tests/templates/import-macro-call-undefined-macro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% import 'macro-call-undefined-macro.html' as t %}
{% for el in list %}
{{ t.defined_macro() }}
{% endfor %}
3 changes: 3 additions & 0 deletions tests/templates/macro-call-undefined-macro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro defined_macro(useless) %}
{% include "undefined-macro.html" %}
{% endmacro %}
1 change: 1 addition & 0 deletions tests/templates/undefined-macro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ undef() }}

0 comments on commit b638d15

Please sign in to comment.