Skip to content

Commit

Permalink
Merge pull request #687 from tgabi333/master
Browse files Browse the repository at this point in the history
fix autoescape for empty includes
  • Loading branch information
RobLoach authored Dec 16, 2019
2 parents 788437f + e8f15bd commit 70c0fcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/twig.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,12 @@ module.exports = function (Twig) {
return '';
}

return new Twig.Markup(escapedOutput.join(''), true);
const joinedOutput = escapedOutput.join('');
if (joinedOutput.length === 0) {
return '';
}

return new Twig.Markup(joinedOutput, true);
};

// Namespace for template storage and retrieval
Expand Down
9 changes: 9 additions & 0 deletions test/test.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ describe('Twig.js Core ->', function () {
}).should.equal('<p>&lt;test&gt;&amp;&lt;/test&gt;</p>');
});

it('should autoescape handle empty include', function () {
twig({id: 'included-return', data: ''});
twig({
allowInlineIncludes: true,
autoescape: true,
data: '{% include "included-return" %}'
}).render().should.equal('');
})

it('should use a correct context in the extended template', function () {
twig({id: 'parent', data: '{% block body %}{{ value }}{% endblock body %}'});
twig({
Expand Down

0 comments on commit 70c0fcd

Please sign in to comment.