From a508ec11618431ac0806ca35ab7aa2d55cf3d53c Mon Sep 17 00:00:00 2001 From: "Fernando H. Silva" Date: Mon, 23 Jan 2012 21:26:38 -0200 Subject: [PATCH] Fixed: Recover last escape value after {% endautoescape %} tag. --- lib/parser.js | 2 +- tests/tags.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/parser.js b/lib/parser.js index a5e54438..e3e93a55 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -214,7 +214,7 @@ exports.parse = function (data, tags, autoescape) { if (index > 0 && (/^end/).test(tagname)) { lastToken = _.last(stack[stack.length - 2]); if ('end' + lastToken.name === tagname) { - if (_.last(stack).name === 'autoescape') { + if (lastToken.name === 'autoescape') { escape = last_escape; } stack.pop(); diff --git a/tests/tags.test.js b/tests/tags.test.js index 750ce678..eba5010b 100644 --- a/tests/tags.test.js +++ b/tests/tags.test.js @@ -37,6 +37,12 @@ exports.autoescape = testCase({ test.done(); }, + off_after_close_tag: function (test) { + var tpl = swig.compile('{% autoescape off %}{% endautoescape %}{{ foo }}'); + test.strictEqual(tpl({ foo: '<\'single\' & "double" quotes>' }), '<'single' & "double" quotes>'); + test.done(); + }, + js: function (test) { var tpl = swig.compile('{% autoescape on "js" %}{{ foo }}{% endautoescape %}'); test.strictEqual(tpl({ foo: '"double quotes" and \'single quotes\'' }), '\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027');