Merge pull request #48 from jasondavies/master.

Fix multi-backslash escaping
This commit is contained in:
Yehuda Katz
2011-05-03 18:59:59 -07:00
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -646,7 +646,7 @@ Handlebars.JavaScriptCompiler = function() {};
quotedString: function(str) {
return '"' + str
.replace(/\\/, '\\\\')
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r') + '"';
+2 -1
View File
@@ -72,7 +72,8 @@ test("newlines", function() {
test("escaping text", function() {
shouldCompileTo("Awesome's", {}, "Awesome's", "text is escaped so that it doesn't get caught on single quotes");
shouldCompileTo("Awesome\\", {}, "Awesome\\", "text is escaped so that the closing quote can't be ignored");
shouldCompileTo("Awesome\\ foo", {}, "Awesome\\ foo", "text is escaped so that it doesn't mess up backslashes");
shouldCompileTo("Awesome\\\\ foo", {}, "Awesome\\\\ foo", "text is escaped so that it doesn't mess up backslashes");
shouldCompileTo("Awesome {{foo}}", {foo: '\\'}, "Awesome \\", "text is escaped so that it doesn't mess up backslashes");
shouldCompileTo(' " " ', {}, ' " " ', "double quotes never produce invalid javascript");
});