sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
365 stars 84 forks source link

Exception when using unescaped characters #183

Open antunesl opened 5 years ago

antunesl commented 5 years ago

Hi, I think I was able to reproduce the same (or at least similar) behavior as reported in this bug: JsFiddle Sample

  1. Start searching 'Some Text'
  2. Select that option (everything behaves normal)
  3. Start searching 'Some Text With (parenthesis)'
  4. Select that option
  5. Start deleting the input using backspace (from the end), it raises this exception:
    jquery.flexdatalist.min.js:2 Uncaught SyntaxError: Invalid regular expression: /Another Text With (parenth/: Unterminated group
    at new RegExp (<anonymous>)
    at Object.highlight (jquery.flexdatalist.min.js:2)
    at Object.matches (jquery.flexdatalist.min.js:2)
    at Object.get (jquery.flexdatalist.min.js:2)
    at jquery.flexdatalist.min.js:2
    at jquery.flexdatalist.min.js:2
    at Object.datalist (jquery.flexdatalist.min.js:2)
    at jquery.flexdatalist.min.js:2
    at Object.static (jquery.flexdatalist.min.js:2)
    at jquery.flexdatalist.min.js:2

    jquery: v3.3.1 jquery-flexdatalist: v2.2.4

The problem seems to be when using the 'searchContain: true', where the regexs are used, and maybe the parenthesis characteres are not being escaped correctly.

Hope this helps.

Thanks @sergiodlopes for a great plugin!