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

Improve 'json-prune' — logging null #282

Closed
AdamWr opened this issue Jan 16, 2023 · 0 comments
Closed

Improve 'json-prune' — logging null #282

AdamWr opened this issue Jan 16, 2023 · 0 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Jan 16, 2023

If there is something like JSON.parse(null); and we use #%#//scriptlet('json-prune'), then script throws error.

Steps to reproduce

  1. Add this rule:
example.org#%#//scriptlet('json-prune')
  1. Go to - https://example.org/
  2. Run in browser console:
(() => {
  console.log('start');
  JSON.parse(null);
  console.log('end');
})();
Screenshot

image

Uncaught TypeError: Cannot convert undefined or null to object

If I'm not wrong, the problem is with isEmptyObject:

export const isEmptyObject = (obj) => Object.keys(obj).length === 0 && !obj.prototype;

It throws error for null.


Related to - AdguardTeam/AdguardFilters#140217
Website is broken after adding rule like this:

crackle.com#%#//scriptlet('json-prune')

to user rules.

@adguard-bot adguard-bot assigned zzebrum and unassigned zzebrum Jan 16, 2023
@adguard-bot adguard-bot changed the title Improve json-prune - fix issue with logging null Improve 'json-prune' — fix issue with logging 'null' Jan 16, 2023
adguard pushed a commit that referenced this issue Feb 28, 2023
Squashed commit of the following:

commit b4a5884
Merge: 98cedec 85e6beb
Author: Adam Wróblewski <[email protected]>
Date:   Tue Feb 28 15:14:09 2023 +0100

    Merge branch 'master' into fix/AG-18869

commit 98cedec
Author: Adam Wróblewski <[email protected]>
Date:   Mon Feb 27 18:05:45 2023 +0100

    Remove objectToString from import
    and related helpers
    Update comment
    Update logMessage description

commit 3cda968
Author: Adam Wróblewski <[email protected]>
Date:   Wed Feb 22 13:01:35 2023 +0100

    Fix test

commit 68cf621
Author: Adam Wróblewski <[email protected]>
Date:   Tue Feb 21 16:58:23 2023 +0100

    Fix issue with logging null
    Improve logging
@adguard-bot adguard-bot changed the title Improve 'json-prune' — fix issue with logging 'null' Improve 'json-prune' — logging null Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants