From 1fb7b51ee6bb8f4a2e395821a4648333a699a982 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 12 Jul 2014 11:43:45 -0500 Subject: [PATCH] Fix rendering of paths that resolve to zero Fixes #820 --- lib/handlebars/compiler/javascript-compiler.js | 2 +- spec/regressions.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index b2baad467..2d4b11569 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -369,7 +369,7 @@ JavaScriptCompiler.prototype = { return ' != null ? ' + lookup + ' : ' + current; } else { // Otherwise we can use generic falsy handling - return ' && ' + lookup; + return ' != null && ' + lookup; } }, true); } diff --git a/spec/regressions.js b/spec/regressions.js index 214a14235..c633a212d 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -122,6 +122,10 @@ describe('Regressions', function() { shouldCompileTo('{{#foo}} This is {{bar}} ~ {{/foo}}', {foo: 0, bar: 'OK'}, ' This is ~ '); }); + it('GH-820: zero pathed rendering', function() { + shouldCompileTo('{{foo.bar}}', {foo: 0}, ''); + }); + if (Handlebars.AST) { it("can pass through an already-compiled AST via compile/precompile", function() { equal(Handlebars.compile(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")]))(), 'Hello');