From 671c07e6992d3094f3c06f2552fe1ab414ddec44 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 6 Apr 2013 14:46:04 -0500 Subject: [PATCH] Force toString in escapeExpression Fixes #211 --- dist/handlebars.js | 5 +++++ dist/handlebars.runtime.js | 5 +++++ lib/handlebars/utils.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/dist/handlebars.js b/dist/handlebars.js index 5bd69b5c8..7942d5e9a 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -825,6 +825,11 @@ Handlebars.Utils = { return ""; } + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = string.toString(); + if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); }, diff --git a/dist/handlebars.runtime.js b/dist/handlebars.runtime.js index 4779ad0a3..1c9b9225a 100644 --- a/dist/handlebars.runtime.js +++ b/dist/handlebars.runtime.js @@ -211,6 +211,11 @@ Handlebars.Utils = { return ""; } + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = string.toString(); + if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); }, diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 85c1a9408..7d9da1741 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -47,6 +47,11 @@ Handlebars.Utils = { return ""; } + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = string.toString(); + if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); },