Skip to content

Fix 'set-constant' — setProxyTrap() #403

@AdamWr

Description

@AdamWr

Currently it doesn't work correctly for falsy values.

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('set-constant', 'foo.bar.test', 'true', '', '', 'true')
  1. Go to - https://example.org/
  2. In browser console run:
Code:
foo = {
  bar: {
    abc: {}
  }
};
console.log('Original foo.bar - foo.bar.test:', foo.bar.test);
foo.bar = {
  abc: {},
};
console.log('Rewritten foo.bar - foo.bar.test:', foo.bar.test);

or

Code:
foo = {
  bar: {
    abc: {}
  }
};
console.log('Original foo.bar - foo.bar.test:', foo.bar.test);
foo.bar = {
  abc: {},
  test: false,
};
console.log('Rewritten foo.bar - foo.bar.test:', foo.bar.test);

foo.bar.test should returns true.

Probably currentObj && should be removed from:

if (currentObj && index === array.length - 1 && currentObj !== constantValue) {

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions