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

fix: Ensure overloaded Array.prototype won't crash axe #615

Merged
merged 1 commit into from
Nov 23, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});