Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

md-autocomplete SyntaxError: Invalid regular expression: /^?/: Nothing to repeat #2292

Closed
BenjaminHofstetter opened this issue Apr 13, 2015 · 1 comment
Assignees

Comments

@BenjaminHofstetter
Copy link

I have items in my autocomplete array starting with a '?' character. This leas to the following error message:

SyntaxError: Invalid regular expression: /^?/: Nothing to repeat
    at new RegExp (native)
    at Object.fn (http://xx/js/angular-material.js:10442:23)
    at m.$get.m.$digest (http://xx/js/angular.min.js:128:172)
   ...

I found that the sanitize function does not escape the question mark. I changed

function sanitize (term) {
      if (!term) return term;
      return term.replace(/[\*\[\]\(\)\{\}\\\^\$]/g, '\\$&');
}

to

function sanitize (term) {
      if (!term) return term;
      return term.replace(/[\?\*\[\]\(\)\{\}\\\^\$]/g, '\\$&');
}

and this solved my problem. Or is it even better to escape all these?

\\ \^ \$ \* \+ \? \. \( \) \| \{ \} \[ \]
@robertmesserle
Copy link
Contributor

@BenjaminHofstetter Excellent find, thanks! Submitted a fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants