Skip to content

Commit

Permalink
Support named endblock tags, fix #521
Browse files Browse the repository at this point in the history
ricordisamoa committed Jan 20, 2016
1 parent 13b384c commit d0400bb
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -399,12 +399,15 @@ var Parser = Object.extend({
this.advanceAfterBlockEnd(tag.value);

node.body = this.parseUntilBlocks('endblock');
this.skipSymbol('endblock');
this.skipSymbol(node.name.value);

if(!this.peekToken()) {
var tok = this.peekToken();
if(!tok) {
this.fail('parseBlock: expected endblock, got end of file');
}

this.advanceAfterBlockEnd();
this.advanceAfterBlockEnd(tok.value);

return node;
},
7 changes: 7 additions & 0 deletions tests/parser.js
Original file line number Diff line number Diff line change
@@ -289,6 +289,9 @@
n = parser.parse('{% block foo %}stuff{% endblock %}');
expect(n.children[0].typename).to.be('Block');

n = parser.parse('{% block foo %}stuff{% endblock foo %}');
expect(n.children[0].typename).to.be('Block');

n = parser.parse('{% extends "test.html" %}stuff');
expect(n.children[0].typename).to.be('Extends');

@@ -674,6 +677,10 @@
parser.parse('hello {% block sdf %} data');
}).to.throwException(/expected endblock/);

expect(function() {
parser.parse('hello {% block sdf %} data{% endblock foo %}');
}).to.throwException(/expected block end/);

expect(function() {
parser.parse('hello {% bar %} dsfsdf');
}).to.throwException(/unknown block tag/);

0 comments on commit d0400bb

Please sign in to comment.