Skip to content

Commit

Permalink
Fix linter complaints (#5735)
Browse files Browse the repository at this point in the history
* remove unnecessary backtracking from mode extension regexp

* remove unused code triggering csp warnings

* add empty group when testing mode regexps to match the actual usage
  • Loading branch information
nightwing authored Feb 3, 2025
1 parent 77b9fe1 commit 75fae83
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 94 deletions.
63 changes: 1 addition & 62 deletions lib/ace/mode/javascript/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3265,68 +3265,7 @@ module.exports = slice;
// and correctly escapes quotes within interpolated code.
// NB: `oldSettings` only exists for backwards compatibility.
function template(text, settings, oldSettings) {
if (!settings && oldSettings) settings = oldSettings;
settings = defaults({}, settings, _$1.templateSettings);

// Combine delimiters into one regular expression via alternation.
var matcher = RegExp([
(settings.escape || noMatch).source,
(settings.interpolate || noMatch).source,
(settings.evaluate || noMatch).source
].join('|') + '|$', 'g');

// Compile the template source, escaping string literals appropriately.
var index = 0;
var source = "__p+='";
text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
source += text.slice(index, offset).replace(escapeRegExp, escapeChar);
index = offset + match.length;

if (escape) {
source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
} else if (interpolate) {
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
} else if (evaluate) {
source += "';\n" + evaluate + "\n__p+='";
}

// Adobe VMs need the match returned to produce the correct offset.
return match;
});
source += "';\n";

var argument = settings.variable;
if (argument) {
// Insure against third-party code injection. (CVE-2021-23358)
if (!bareIdentifier.test(argument)) throw new Error(
'variable is not a bare identifier: ' + argument
);
} else {
// If a variable is not specified, place data values in local scope.
source = 'with(obj||{}){\n' + source + '}\n';
argument = 'obj';
}

source = "var __t,__p='',__j=Array.prototype.join," +
"print=function(){__p+=__j.call(arguments,'');};\n" +
source + 'return __p;\n';

var render;
try {
render = new Function(argument, '_', source);
} catch (e) {
e.source = source;
throw e;
}

var template = function(data) {
return render.call(this, data, _$1);
};

// Provide the compiled source as a convenience for precompilation.
template.source = 'function(' + argument + '){\n' + source + '}';

return template;
console.error("should not happen");
}

// Traverses the children of `obj` along `path`. If a child is a function, it
Expand Down
32 changes: 1 addition & 31 deletions lib/ace/mode/yaml/yaml-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3500,37 +3500,7 @@ function resolveJavascriptFunction(data) {
}

function constructJavascriptFunction(data) {
/*jslint evil:true*/

var source = '(' + data + ')',
ast = esprima.parse(source, { range: true }),
params = [],
body;

if (ast.type !== 'Program' ||
ast.body.length !== 1 ||
ast.body[0].type !== 'ExpressionStatement' ||
(ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
ast.body[0].expression.type !== 'FunctionExpression')) {
throw new Error('Failed to resolve function');
}

ast.body[0].expression.params.forEach(function (param) {
params.push(param.name);
});

body = ast.body[0].expression.body.range;

// Esprima's ranges include the first '{' and the last '}' characters on
// function expressions. So cut them out.
if (ast.body[0].expression.body.type === 'BlockStatement') {
/*eslint-disable no-new-func*/
return new Function(params, source.slice(body[0] + 1, body[1] - 1));
}
// ES6 arrow functions can omit the BlockStatement. In that case, just return
// the body.
/*eslint-disable no-new-func*/
return new Function(params, 'return ' + source.slice(body[0], body[1]));
return function() {}
}

function representJavascriptFunction(object /*, style*/) {
Expand Down
2 changes: 1 addition & 1 deletion src/ext/modelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Mode {
}) + "$";
}
else {
re = "^.*\\.(" + extensions + ")$";
re = "\\.(" + extensions + ")$";
}

this.extRe = new RegExp(re, "gi");
Expand Down
1 change: 1 addition & 0 deletions src/mode/_test/highlight_rules_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ function checkBacktracking(tokenizer) {
var regex = rule.regex;
if (regex && typeof regex != "string") regex = regex.source;
if (!regex) return;
regex = "(" + regex + ")|";
var result = require("recheck").checkSync(regex, "gmi", {
checker: "automaton",
timeout: 100000
Expand Down

0 comments on commit 75fae83

Please sign in to comment.