iissnan / hexo-theme-next

Elegant theme for Hexo.
http://notes.iissnan.com
MIT License
15.87k stars 3.62k forks source link

Bugs in negated `instanceof` expressions #2270

Open gorosgobe opened 1 year ago

gorosgobe commented 1 year ago

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 a potentially problematic instance of the above bugs in your codebase: https://github.com/iissnan/hexo-theme-next/blob/9c8cea69bf0d4f91c07779d71b01814b27bbb6a1/source/lib/Han/dist/han.js#L2154

LauArmy commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

stevenjoezhang commented 5 months ago

You can report it here: https://github.com/ethantw/Han/issues

See https://github.com/ethantw/Han/blob/970d163c6af207027931dcde02c1cb7138de32c9/src/js/locale/h-ruby.js#L186

LauArmy commented 3 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。