Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
fixing filter argument parsing from macros breaking them
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Sep 24, 2011
1 parent 58db4c9 commit 1d53aaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/helpers.js
Expand Up @@ -152,7 +152,7 @@ exports.wrapFilter = function (variable, filter) {
if (filters.hasOwnProperty(filter.name)) {
args = [variable];
filter.args.forEach(function (f) {
args.push('\'' + f.replace(/\\/g, '\\\\') + '\'');
args.push('\'' + f.replace(/\\/g, '\\\\').replace(/^\"|\"$/g, '') + '\'');
});
output = '__filters.' + filter.name + '.apply(this, [' + args.toString() + '])';
}
Expand Down
10 changes: 5 additions & 5 deletions lib/parser.js
Expand Up @@ -24,29 +24,29 @@ function getMethod(input) {

function getArgs(input) {
var parts = input.replace(/^\w+\(|\)$/g, '').split(', '),
i = parts.length,
l = parts.length,
i = 0,
part = '',
partial = '',
out = [];

while (i) {
i -= 1;
for (; i < l; i += 1) {
part = parts[i];
if ((/^\'|^\"/).test(part) && !(/\"$|\'$/).test(part)) {
partial = part;
continue;
}

if (partial !== '') {
partial += part;
partial += ', ' + part;
if (!(/\"$|\'$/).test(partial)) {
continue;
}
part = partial;
}
out.push(part);
}
return parts;
return out;
}

function parseVariable(token, escape) {
Expand Down
3 changes: 3 additions & 0 deletions tests/templates.test.js
Expand Up @@ -60,6 +60,9 @@ exports.Variables = testCase({

var tmpl8 = swig.fromString('{{ asdf|lower }}');
test.strictEqual(tmpl8.render({ asdf: 'BLAH' }), 'blah');

tmpl8 = swig.fromString('{{ date|date("F jS, Y") }}');
test.strictEqual(tmpl8.render({ date: new Date(2011, 8, 24) }), 'September 24th, 2011');
test.done();
},

Expand Down

0 comments on commit 1d53aaf

Please sign in to comment.