From c23906bc7d807f5123ca39ea17103b39434826d7 Mon Sep 17 00:00:00 2001 From: mde Date: Sat, 6 Feb 2021 12:21:24 -0800 Subject: [PATCH 1/2] Sanitize filename for display --- lib/ejs.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ejs.js b/lib/ejs.js index 51b202e6..a795ea66 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -569,6 +569,8 @@ Template.prototype = { var appended = ''; var escapeFn = opts.escapeFunction; var ctor; + /** @type {string} */ + var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : 'undefined'; if (!this.source) { this.generateSource(); @@ -600,8 +602,7 @@ Template.prototype = { if (opts.compileDebug) { src = 'var __line = 1' + '\n' + ' , __lines = ' + JSON.stringify(this.templateText) + '\n' - + ' , __filename = ' + (opts.filename ? - JSON.stringify(opts.filename) : 'undefined') + ';' + '\n' + + ' , __filename = ' + sanitizedFilename + ';' + '\n' + 'try {' + '\n' + this.source + '} catch (e) {' + '\n' @@ -627,7 +628,7 @@ Template.prototype = { } if (opts.compileDebug && opts.filename) { src = src + '\n' - + '//# sourceURL=' + opts.filename + '\n'; + + '//# sourceURL=' + sanitizedFilename + '\n'; } try { From a0e0f301657a902770d96356f9ebcadee2b03311 Mon Sep 17 00:00:00 2001 From: Stefan Seide Date: Wed, 10 Feb 2021 12:11:36 +0100 Subject: [PATCH 2/2] update sourceUrl string as commented by ExE-Boss --- lib/ejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ejs.js b/lib/ejs.js index a795ea66..f8413b57 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -628,7 +628,7 @@ Template.prototype = { } if (opts.compileDebug && opts.filename) { src = src + '\n' - + '//# sourceURL=' + sanitizedFilename + '\n'; + + '//# sourceURL=' + encodeURI(opts.filename) + '\n'; } try {