Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid filtering due to using "RegExp.test()" #56

Closed
kfbishop opened this issue Feb 16, 2016 · 2 comments
Closed

Invalid filtering due to using "RegExp.test()" #56

kfbishop opened this issue Feb 16, 2016 · 2 comments

Comments

@kfbishop
Copy link
Contributor

After banging my head for most of a day, I've stumbled upon an odd side-effect caused by using "RegExp.text() in select.ts:filter() (line ~515). Seems RegExp keeps a back reference from the last test, which negates the next test! Changing the code to use .match() resolves this issue, at the theoretical expense of performance.

This can be verified / tested using the following plunker
Ng2 test() v match() test

References:

  • MDN text() - test() called multiple times on the same global regular expression instance will advance past the previous match
  • S/O (final answer)
@kfbishop
Copy link
Contributor Author

components/select/select.ts: Line 517

Was: .filter(option => query.test(option.text) &&
To be: .filter(option => option.text.match(query) &&

@valorkin valorkin changed the title Invalid filtering due to using "RegExp.text()" Invalid filtering due to using "RegExp.test()" Feb 22, 2016
@valorkin
Copy link
Member

@kfbishop https://github.com/valor-software/ng2-select/pull/57/commits
there a lot of commits
from which I will not be able to generate changelog

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

No branches or pull requests

2 participants