From 93fb25c702aeb787fd3af2c7bb67e625d399762e Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 23 Dec 2013 15:33:33 -0600 Subject: [PATCH] Handle empty responses from partials Fixes #675 --- lib/handlebars/runtime.js | 4 ++-- spec/partials.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 65fa85f64..aa0f13e08 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -33,7 +33,7 @@ export function template(templateSpec, env) { // TODO : Check this for all inputs and the options handling (partial flag, etc). This feels // like there should be a common exec path var result = invokePartial.apply(this, arguments); - if (result) { return result; } + if (result != null) { return result; } var options = { helpers: helpers, partials: partials, data: data }; partials[name] = env.compile(partial, { data: data !== undefined }, env); @@ -42,7 +42,7 @@ export function template(templateSpec, env) { } else { invokePartialWrapper = function(partial, name /* , context, helpers, partials, data */) { var result = invokePartial.apply(this, arguments); - if (result) { return result; } + if (result != null) { return result; } throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode"); }; } diff --git a/spec/partials.js b/spec/partials.js index 3f46c377a..bea72f5b7 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -123,4 +123,10 @@ describe('partials', function() { var hash = {name:"Jeepers", another_dude:"Creepers"}; shouldCompileToWithPartials(string, [hash, {}, {'+404/asdf?.bar':dude}], true, "Dudes: Jeepers", "Partials can use literal paths"); }); + + it('should handle empty partial', function() { + var string = "Dudes: {{#dudes}}{{> dude}}{{/dudes}}"; + var partial = ""; + var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]}; + shouldCompileToWithPartials(string, [hash, {}, {dude: partial}], true, "Dudes: "); }); });