diff --git a/lib/template/adapters/ejs/template.js b/lib/template/adapters/ejs/template.js index 1dc17489..455e6d92 100644 --- a/lib/template/adapters/ejs/template.js +++ b/lib/template/adapters/ejs/template.js @@ -171,8 +171,13 @@ ejs.Template.prototype = new function () { this.scanLine = function (line) { var _this = this; var _addOutput = function () { + // Preserve literal slashes + line = line.replace(/\\/g, '\\\\'); + // Convert linebreaks line = line.replace(/\n/, '\\n'); - line = line.replace(/\r/, ''); + line = line.replace(/\r/, '\\r'); + // Escape double-quotes -- this will be the delimiter + // during execution line = line.replace(/"/g, '\\"'); _this.source += '_output += "' + line + '";'; };