rules-machine icon indicating copy to clipboard operation
rules-machine copied to clipboard

Restrict allowed variable symbols & reserved words

Open justsml opened this issue 2 years ago • 0 comments

For all variable/token names:

  • [ ] Prevent any special symbols or operators in names.
    • [ ] Opt 1: Filtering ~``!@#$%^&*()-_=+{}|[]\;:'<>?,./ - exclusionary approach can allow strange edge cases and must account for the endless strangeness of Unicode special symbols.
    • [ ] Opt 2: Must match ^[a-zA-Z0-9\.\-_]+$ - restricted can limit use cases, but much safer.
  • [ ] Exclude all builtin JS functions & internal operation names.
    • [ ] parseInt, parseFloat, (there's an NPM package with arrays of this...)
    • [ ] Get a dynamic list of prefixOps and infixOps. (need to export from the expression-language/index.)
  • [ ] No lone or dotted numbers (avoids some array/index collisions & weirdness.)
    • [ ] ❌ 42 = 'Antwerd'
    • [ ] ❌ 42.24 = 'Antwerd'
    • [ ] ✅ words[42] = 'Antwerd'
  • [ ] Throw error on dangerous Object.prototype.... methods.
    • [ ] valueOf, toString, toJSON, etc.

justsml avatar May 20 '22 17:05 justsml