From e3d128b2f615fa87ed0d7775217a6cfbb7a37883 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 6 Sep 2019 18:00:00 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Allow=C2=A0disabling=20legacy=C2=A0`inc?= =?UTF-8?q?lude`=20preprocessor=C2=A0directives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/jsdoc/options.jsdoc | 8 ++++++++ lib/ejs.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/jsdoc/options.jsdoc b/docs/jsdoc/options.jsdoc index 5b6fdb18..2edb1d5c 100644 --- a/docs/jsdoc/options.jsdoc +++ b/docs/jsdoc/options.jsdoc @@ -71,6 +71,14 @@ * Whether or not to create an async function instead of a regular function. * This requires language support. * + * @property {boolean} [legacyInclude=true] + * Whether to enable legacy preprocessor include directives. + * + * **Example:** + * ```ejs + * <%- include foo %> + * ``` + * * @static * @global */ diff --git a/lib/ejs.js b/lib/ejs.js index c65354c8..b011424d 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -526,6 +526,7 @@ function Template(text, opts) { options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME; options.views = opts.views; options.async = opts.async; + options.legacyInclude = typeof opts.legacyInclude != 'undefined' ? !!opts.legacyInclude : true; if (options.strict) { options._with = false; @@ -711,7 +712,7 @@ Template.prototype = { } } // HACK: backward-compat `include` preprocessor directives - if ((include = line.match(/^\s*include\s+(\S+)/))) { + if (opts.legacyInclude && (include = line.match(/^\s*include\s+(\S+)/))) { opening = matches[index - 1]; // Must be in EVAL or RAW mode if (opening && (opening == o + d || opening == o + d + '-' || opening == o + d + '_')) {