From cd3ca61ec345cfd4c983047018a91332e4cd3176 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Wed, 11 Jul 2012 20:48:47 -0700 Subject: [PATCH] ignore extra block helper args as intended --- packages/handlebars/evaluate.js | 6 ++++-- packages/templating/templating_tests.html | 1 + packages/templating/templating_tests.js | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/handlebars/evaluate.js b/packages/handlebars/evaluate.js index efb78cf829..68a01ddbba 100644 --- a/packages/handlebars/evaluate.js +++ b/packages/handlebars/evaluate.js @@ -224,10 +224,12 @@ Handlebars.evaluate = function (ast, data, options) { if (isNested && values.length > 1) { // at least one positional argument; not no args // or only hash args. - if (typeof values[1] === "function") + var oneArg = values[1]; + if (typeof oneArg === "function") // invoke the positional arguments // (and hash arguments) as a nested helper invocation. - values = [values[0], apply(values.slice(1), {hash:hash})]; + oneArg = apply(values.slice(1), {hash:hash}); + values = [values[0], oneArg]; // keyword args don't go to the block helper, then. extra.hash = {}; } else { diff --git a/packages/templating/templating_tests.html b/packages/templating/templating_tests.html index 876eb7ac07..779b2122ea 100644 --- a/packages/templating/templating_tests.html +++ b/packages/templating/templating_tests.html @@ -181,4 +181,5 @@ (nokeys={{#arg_and_dict "foo" x="foo"}}{{/arg_and_dict}}) (nokeys={{#arg_and_dict tree x="foo"}}{{/arg_and_dict}}) (biggie={{#get_arg helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns}}{{/get_arg}}) + (twoArgBlock={{#two_args "foo" "foo"}}{{/two_args}}) diff --git a/packages/templating/templating_tests.js b/packages/templating/templating_tests.js index 8bef0d764a..046a769213 100644 --- a/packages/templating/templating_tests.js +++ b/packages/templating/templating_tests.js @@ -292,6 +292,10 @@ Tinytest.add("templating - helpers and dots", function(test) { Template.test_helpers_i.get_arg = function(arg) { return arg; }; + Template.test_helpers_i.two_args = function(arg1, arg2) { + return [typeof arg1 === "string", + typeof arg2 === "string"].join(); + }; Template.test_helpers_i.helperListFour = listFour; trials = @@ -305,5 +309,7 @@ Tinytest.add("templating - helpers and dots", function(test) { test.equal(trials[3], "(nokeys=0)"); test.equal(trials[4], '(biggie=eggs leaf guava 0 a:eggs b:leaf c:guava d:0)'); - test.equal(trials.length, 5); + // can't pass > 1 positional arg to block helper + test.equal(trials[5], "(twoArgBlock=true,false)"); + test.equal(trials.length, 6); });