Skip to content

Commit

Permalink
fix: Ensure overloaded Array.prototype won't crash axe
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Nov 14, 2017
1 parent 63040bd commit ea57ef2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core/public/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function runCommand(data, keepalive, callback) {
};

var context = (data && data.context) || {};
if (context.include && !context.include.length) {
if (context.hasOwnProperty('include') && !context.include.length) {
context.include = [document];
}
var options = (data && data.options) || {};
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/rule-should-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function matchTags(rule, runOnly) {
var defaultExclude = (axe._audit && axe._audit.tagExclude) ? axe._audit.tagExclude : [];

// normalize include/exclude
if (runOnly.include || runOnly.exclude) {
if (runOnly.hasOwnProperty('include') || runOnly.hasOwnProperty('exclude')) {
// Wrap include and exclude if it's not already an array
include = runOnly.include || [];
include = Array.isArray(include) ? include : [include];
Expand Down
28 changes: 27 additions & 1 deletion test/core/public/run-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('runRules', function () {
}
}], messages: {}});


var frame = document.createElement('iframe');
frame.src = '../mock/frames/frame-frame.html';

Expand Down Expand Up @@ -621,4 +620,31 @@ describe('runRules', function () {
});
fixture.appendChild(frame);
});

it('should not fail if `include` / `exclude` is overwritten', function (done) {
function invalid () {
throw new Error('nope!');
}
Array.prototype.include = invalid;
Array.prototype.exclude = invalid;

axe._load({ rules: [{
id: 'html',
selector: 'html',
any: ['html']
}], checks: [{
id: 'html',
evaluate: function () {
return true;
}
}], messages: {}});

runRules([document], {}, function (r) {
assert.lengthOf(r[0].passes, 1);

delete Array.prototype.include;
delete Array.prototype.exclude;
done();
}, isNotCalled);
});
});

0 comments on commit ea57ef2

Please sign in to comment.