marionebl / svg-term-cli

Share terminal sessions via SVG and CSS
MIT License
3.48k stars 116 forks source link

Use `hasOwnProperty` instead of `in` #22

Closed adius closed 6 years ago

adius commented 6 years ago

https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey

marionebl commented 6 years ago

Are you hitting bugs in usage with the right hand binding being null or undefined?

All the x in y checks in svg-term-cli happen on shallow objects without protoype chain, so there should be no pressing reason to use hasOwnProperty.

adius commented 6 years ago

shallow objects without protoype chain

Even they have properties:

"toString" in ({foo:"bar"}) yields true

You need to make sure that you cli flags never match with one of the default properties. Also they could add new properties in future JavaScript version, and then your code would suddenly break. It's really dangerous and just not worth the little syntax sugar.

marionebl commented 6 years ago

Understood. This could increase the sturdiness of the CLI. As of now this a "third line of defense" type of thing, the first two being:

  1. All checked objects created by the program
  2. Unknown flags not allowed
adius commented 6 years ago

In JavaScript you can't have enough lines of defense. It's such a broken language. 🙈 Even TypeScript can't really help. I switched to PureScript because of this. It's such a pleasure 😍.

Just wanted to make sure you're aware of the situation.