diff options
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r-- | lib/handlebars/utils.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index fc2b846..41495e1 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -60,21 +60,23 @@ export function indexOf(array, value) { export function escapeExpression(string) { - // don't escape SafeStrings, since they're already safe - if (string && string.toHTML) { - return string.toHTML(); - } else if (string == null) { - return ""; - } else if (!string) { - return string + ''; - } + if (typeof string !== 'string') { + // don't escape SafeStrings, since they're already safe + if (string && string.toHTML) { + return string.toHTML(); + } else if (string == null) { + return ''; + } else if (!string) { + return string + ''; + } - // 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; + // 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; + } - if(!possible.test(string)) { return string; } + if (!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); } |