icindy / wxParse

wxParse-微信小程序富文本解析自定义组件,支持HTML及markdown解析
http://weappdev.com/
MIT License
7.75k stars 1.82k forks source link

Bugs in negated `instanceof` expressions #378

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/icindy/wxParse/blob/9d5df482294b7d39f8802d413f25d28d0d6c349e/wxParse/showdown.js#L2263