From c35be3530a1518e6f2f200b4b49706e82e771861 Mon Sep 17 00:00:00 2001 From: Tyler Blackham Date: Tue, 2 Dec 2025 10:21:22 -0700 Subject: [PATCH] fix: allow the evaluation of null characters --- spec/compiler.js | 16 ++++++++++++++++ src/handlebars.l | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/compiler.js b/spec/compiler.js index fe394b720..a391779c0 100644 --- a/spec/compiler.js +++ b/spec/compiler.js @@ -149,6 +149,22 @@ describe('compiler', function() { JSON.stringify({ knownHelpers: {} }, 0, 2) ); }); + + it('should compile and render templates containing a null character(GH-2059)', function() { + var nul = String.fromCharCode(0); + var templateSource = 'Hello ' + nul + ' {{name}}'; + var template = Handlebars.compile(templateSource); + equal(template({ name: 'World' }), 'Hello ' + nul + ' World'); + }); + + it('should compile and render templates containing a null character in a mustache expression(GH-2059)', function() { + var nul = String.fromCharCode(0); + var templateSource = 'Hello ' + '{{foo' + nul + 'bar}}'; + var context = {}; + context['foo' + nul + 'bar'] = 'World'; + var template = Handlebars.compile(templateSource); + equal(template(context), 'Hello World'); + }); }); describe('#precompile', function() { diff --git a/src/handlebars.l b/src/handlebars.l index fbf208b48..44db53278 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -28,7 +28,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD} %% -[^\x00]*?/("{{") { +[\s\S]*?/("{{") { if(yytext.slice(-2) === "\\\\") { strip(0,1); this.begin("mu"); @@ -41,10 +41,10 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD} if(yytext) return 'CONTENT'; } -[^\x00]+ return 'CONTENT'; +[\s\S]+ return 'CONTENT'; // marks CONTENT up to the next mustache or escaped mustache -[^\x00]{2,}?/("{{"|"\\{{"|"\\\\{{"|<>) { +[\s\S]{2,}?/("{{"|"\\{{"|"\\\\{{"|<>) { this.popState(); return 'CONTENT'; } @@ -63,7 +63,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD} return 'END_RAW_BLOCK'; } } -[^\x00]+?/("{{{{") { return 'CONTENT'; } +[\s\S]+?/("{{{{") { return 'CONTENT'; } [\s\S]*?"--"{RIGHT_STRIP}?"}}" { this.popState();