Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$$testability: Unexpected behaviour of findBindings with exactMatch === true #9595

Closed
gkalpak opened this issue Oct 13, 2014 · 5 comments
Closed

Comments

@gkalpak
Copy link
Member

gkalpak commented Oct 13, 2014

$$testability.findBindings with opt_exactMatch set to true, uses a RegExp to match the specified expression against an element's bindings which results into unexpected (wrong?) behaviour.

The main problem is that is does not account for characters with special meaning in the context of a regular expression (e.g. $, | etc), which results in matching errors:

E.g. trying to match against the binding $index will produce the following RegExp:
/(^|\s)$index(\s|\||$)/ (which will always fail).

Or trying to match against any binding with a filter will yield unexpected matches (due to the | character).
E.g. trying to match against myValue | transformed will result into the following RegExp:
/(^|\s)myValue | transformed(\s|\||$)/(which would (among other things) erroneously match all bindings starting with myValue).


Off the top of my head, either escaping expression or using string comparison with some additional checks (for leading/trailing characters) would solve this problem, but I am not sure what path we want to go down.
Alternatively, it should be documented somewhere (in protractor's docs?) that trying to do exact matching by binding has certain limitations.

@IgorMinar
Copy link
Contributor

@juliemr can you take a look please?

@juliemr
Copy link
Member

juliemr commented Oct 13, 2014

The $index case seems like a bug that we should fix - I'll make a PR which adds escaping. As for filters, I think this is working as intended and the documentation should just be updated.

@IgorMinar IgorMinar added this to the Backlog milestone Oct 13, 2014
@IgorMinar
Copy link
Contributor

please send us the PR. thanks!

juliemr added a commit to juliemr/angular.js that referenced this issue Oct 13, 2014
…re performing regexp

Move the function to escape regexps to Angular.js, fix the link, and use it in
the $$testability service.

See angular#9595
juliemr added a commit to juliemr/angular.js that referenced this issue Oct 13, 2014
…re performing regexp

Move the function to escape regexps to Angular.js, fix the link, and use it in
the $$testability service.

See angular#9595
juliemr added a commit to juliemr/angular.js that referenced this issue Oct 13, 2014
…re performing regexp

Move the function to escape regexps to Angular.js, fix the link, and use it in
the $$testability service.

See angular#9595
@gkalpak
Copy link
Member Author

gkalpak commented Oct 13, 2014

@juliemr I don't know why you say the filter case was working as expected (maybe I didn't make myself clear), but your fix solves the filter issue as well.

(Just to be clear, what I meant about filters was that the | in e.g. amount | currency has a special meaning in RegExp and (if not escaped) changes the meaning of the RegExp.)

@juliemr
Copy link
Member

juliemr commented Oct 13, 2014

@gkalpak you're right, I misread your comment at first.

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

No branches or pull requests

3 participants