Fix disappearing backslash bug

Backslashes weren't being escaped during compilation, causing templates
containing backslashes to mysteriously lose them.
This commit is contained in:
Jason Davies
2010-09-20 23:44:08 +01:00
parent d374744223
commit 57e990e6e0
2 changed files with 3 additions and 4 deletions
+2 -4
View File
@@ -28,10 +28,6 @@ var Handlebars = {
escapeText: function(string) {
string = string.replace(/'/g, "\\'");
string = string.replace(/\"/g, "\\\"");
if (string.slice(-1) == "\\") {
string = string + "\\";
}
return string;
},
@@ -277,6 +273,8 @@ Handlebars.Compiler.prototype = {
} else if (chr === "\r") {
this.newlines = this.newlines + "\r";
chr = "\\r";
} else if (chr === "\\") {
chr = "\\\\";
}
this.text = this.text + chr;
}
+1
View File
@@ -48,6 +48,7 @@ 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(' " " ', {}, ' " " ', "double quotes never produce invalid javascript");
});