Skip to content

Commit

Permalink
Ensure set = (number) is truly a number
Browse files Browse the repository at this point in the history
Closes gh-53
  • Loading branch information
paularmstrong committed Feb 18, 2012
1 parent 852afd3 commit bda4621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tags/set.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function (indent, parentBlock, parser) {
}

value = thisArgs[0];
if ((/^\'|^\"|^\{|^\[/).test(value) || value === 'true' || value === 'false') {
if (helpers.isLiteral(value) || (/^\{|^\[/).test(value) || value === 'true' || value === 'false') {
return ' ' + varname + ' = ' + value + ';';
}

Expand Down
6 changes: 6 additions & 0 deletions lib/tags/set.test.js
Expand Up @@ -34,5 +34,11 @@ exports.set = testCase({
swig.compile('{% block a %}{{ foo }}{% endblock %}', { filename: 'a' });
test.strictEqual(swig.compile('{% extends "a" %}{% set foo = "bar" %}')(), 'bar');
test.done();
},

'set number is really a number [gh-53]': function (test) {
test.strictEqual(swig.compile('{% set foo = 1 %}{{ foo|add(1) }}')(), '2', 'literal number is a number');
test.strictEqual(swig.compile('{% set foo = "1" %}{{ foo|add(1) }}')(), '11', 'string number is not a number');
test.done();
}
});

0 comments on commit bda4621

Please sign in to comment.