jonschlinkert / data-store

Easily get, set and persist config data. Fast. Supports dot-notation in keys. No dependencies.
https://github.com/jonschlinkert
MIT License
160 stars 27 forks source link

SyntaxError: Invalid regular expression on line 392 #12

Closed hazelmeow closed 6 years ago

hazelmeow commented 6 years ago

https://github.com/jonschlinkert/data-store/blob/master/index.js#L392

This line:

const split = str => str.split(/(?<!\\)\./).map(strip);

Throws an error:

/redacted_path/node_modules/data-store/index.js:392
const split = str => str.split(/(?<!\\)\./).map(strip);
                         ^

SyntaxError: Invalid regular expression: /(?<!\\)\./: Invalid group
    at split (/redacted_path/node_modules/data-store/index.js:392:26)
    at get (/redacted_path/node_modules/data-store/index.js:433:7)
    at Store.has (/redacted_path/node_modules/data-store/index.js:148:19)
    at /redacted_path/redacted_file.js:10:15
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/redacted_path/redacted_file.js:9:11)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)

Changed it to:

const split = str => str.split(/(?!\\)\./).map(strip);

And it hasn't errored yet. I don't know if my fix will break anything though.

jonschlinkert commented 6 years ago

Changed it to:

A negative lookahead won't work. The node version is wrong in package.json, it should be 8.6 I think.

And it hasn't errored yet. I don't know if my fix will break anything though.

Are you saying all of the unit tests passed?

hazelmeow commented 6 years ago

@jonschlinkert haven't run unit tests, but it worked to temporarily fix my project.

hazelmeow commented 6 years ago

Before change:

store
    create
      ✓ should create an instance of Store
      1) should create a store with the given `name`
      ✓ should initialize a store with the given defaults
    set
      2) should `.set()` a value
      ✓ should `.set()` an object
      3) should `.set()` a nested value
      4) should save data that is added directly to `storedata`
    union
      5) should add and arrayify a new value
      6) should uniquify duplicate values
      7) should union an existing value
    has
      8) should return true if a key has a value
      9) should return true if a nested key has a value
    hasOwn
      10) should return true if a key exists
      11) should work with escaped keys
      12) should return true if a nested key exists
    get
      13) should `.get()` a stored value
      14) should `.get()` a nested value
    union
      15) should `.del()` a stored value
    del
      16) should delete stored values
      17) should delete a nested stored value
      18) should ignore nested properties that do not exist
      19) should delete multiple stored values
    json
      20) should use the indent value defined on ctor options

  3 passing (22ms)
  20 failing

...all the fails are because

SyntaxError: Invalid regular expression: /(?<!\\)\./: Invalid group
      at split (index.js:392:26)
      at set (index.js:438:10)
      at Store.set (index.js:73:7)
      at Context.<anonymous> (test/test.js:167:13)

after:

store
    create
      ✓ should create an instance of Store
      ✓ should create a store with the given `name`
      ✓ should initialize a store with the given defaults
    set
      ✓ should `.set()` a value
      ✓ should `.set()` an object
      ✓ should `.set()` a nested value
      ✓ should save data that is added directly to `storedata`
    union
      ✓ should add and arrayify a new value
      ✓ should uniquify duplicate values
      ✓ should union an existing value
    has
      ✓ should return true if a key has a value
      ✓ should return true if a nested key has a value
    hasOwn
      ✓ should return true if a key exists
      1) should work with escaped keys
      ✓ should return true if a nested key exists
    get
      ✓ should `.get()` a stored value
      ✓ should `.get()` a nested value
    union
      ✓ should `.del()` a stored value
    del
      ✓ should delete stored values
      ✓ should delete a nested stored value
      ✓ should ignore nested properties that do not exist
      ✓ should delete multiple stored values
    json
      ✓ should use the indent value defined on ctor options

  22 passing (24ms)
  1 failing

  1) store hasOwn should work with escaped keys:

      AssertionError [ERR_ASSERTION]: false == true
      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/test.js:158:7)
jonschlinkert commented 6 years ago

I eliminated the regex negative lookbehind that caused the error. Thanks for creating the issue