Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support disabling legacy include preprocessor directives #458

Merged
merged 1 commit into from Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/jsdoc/options.jsdoc
Expand Up @@ -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
*/
3 changes: 2 additions & 1 deletion lib/ejs.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + '_')) {
Expand Down