Fix disappearing backslash bug
Backslashes weren't being escaped during compilation, causing templates containing backslashes to mysteriously lose them.
This commit is contained in:
+2
-4
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user