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

Bugs in negated in expressions #2617

Closed
gorosgobe opened this issue Sep 20, 2023 · 1 comment
Closed

Bugs in negated in expressions #2617

gorosgobe opened this issue Sep 20, 2023 · 1 comment
Labels
enhancement A minor feature request

Comments

@gorosgobe
Copy link

Description

in and instanceof expressions in JS

a in obj;
a instanceof C;

can be negated by grouping them and applying the ! operator, i.e.

!(a in obj);
!(a instanceof C);

Applying the ! operator incorrectly (on the LHS operand) leads to bugs:

!a in obj; // will evaluate to false, unless obj has a "true" or "false" key
!a instanceof C; // will evaluate to false, unless C overrides instanceof with a @@hasInstance method

For more information, please see these MDN docs and the no-unsafe-negation recommended Eslint rule.

I have found several potentially problematic instances of the above bugs in your codebase:
https://github.com/SergioBenitez/Rocket/blob/26a3f00f82b6ddec2bbdb3ecb0c29d6ff0da7472/examples/chat/static/script.js#L97

@gorosgobe gorosgobe added the triage A bug report being investigated label Sep 20, 2023
@SergioBenitez SergioBenitez added enhancement A minor feature request and removed triage A bug report being investigated labels Sep 20, 2023
@SergioBenitez
Copy link
Member

SergioBenitez commented Sep 20, 2023

This is an example, which we don't hold to the same standard as the rest of the codebase. And that line of code is only guarding against some rogue requests, which the example will never trigger. No harm in making it better, of course!

SergioBenitez added a commit that referenced this issue Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A minor feature request
Projects
None yet
Development

No branches or pull requests

2 participants