Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
disallowDanglingUnderscores: do not rewrite __proto__ property
Browse files Browse the repository at this point in the history
Fixes #2026
  • Loading branch information
markelog committed Dec 18, 2015
1 parent 89b0440 commit 4158f1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/rules/disallow-dangling-underscores.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ module.exports.prototype = {
identifiers = (identifiers.allExcept).concat(defaultIdentifiers);
}

this._identifierIndex = {};
for (var i = 0, l = identifiers.length; i < l; i++) {
this._identifierIndex[identifiers[i]] = true;
}
this._identifierIndex = identifiers;
},

getOptionName: function() {
Expand All @@ -98,8 +95,9 @@ module.exports.prototype = {

file.iterateTokensByType('Identifier', function(token) {
var value = token.value;

if ((value[0] === '_' || value.slice(-1) === '_') &&
!allowedIdentifiers[value]
allowedIdentifiers.indexOf(value) < 0
) {
errors.add(
'Invalid dangling underscore found',
Expand Down
17 changes: 17 additions & 0 deletions test/specs/rules/disallow-dangling-underscores.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ describe('rules/disallow-dangling-underscores', function() {
checker.configure({ disallowDanglingUnderscores: { allExcept: true } });
}).to.throw();
});

it('should not set property `__proto__` to `true` value (#2026)', function() {
var old = Object.getOwnPropertyDescriptor(Object.prototype,'__proto__');

Object.defineProperty(Object.prototype, '__proto__', {
set: function(newProto) {
expect(newProto).to.not.equal(true);
}
});

expect(function() {
checker.configure({ disallowDanglingUnderscores: true });
}).to.not.throw();

// Beware, if assertion will be incorrect it will break all the subsequent tests
Object.defineProperty(Object.prototype, '__proto__', old);
});
});

describe('option value true', function() {
Expand Down

0 comments on commit 4158f1a

Please sign in to comment.