Skip to content

Commit

Permalink
fix(selector): select by attribute independent of value and order
Browse files Browse the repository at this point in the history
Closes #2513
  • Loading branch information
tbosch committed Jun 15, 2015
1 parent 5bfcca2 commit 9bad70b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/angular2/src/render/dom/compiler/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ export class SelectorMatcher {
result;

var partialValuesMap = MapWrapper.get(this._attrValuePartialMap, attrName);
if (!StringWrapper.equals(attrValue, _EMPTY_ATTR_VALUE)) {
result = this._matchPartial(partialValuesMap, _EMPTY_ATTR_VALUE, cssSelector,
matchedCallback) ||
result;
}
result =
this._matchPartial(partialValuesMap, attrValue, cssSelector, matchedCallback) || result;
}
Expand Down
18 changes: 18 additions & 0 deletions modules/angular2/test/render/dom/compiler/selector_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ export function main() {
expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector))
.toEqual(true);
expect(matched).toEqual([s1[0], 1, s2[0], 2]);

reset();
expect(matcher.match(CssSelector.parse('[someAttr=someValue][someAttr2]')[0],
selectableCollector))
.toEqual(true);
expect(matched).toEqual([s1[0], 1, s2[0], 2]);

reset();
expect(matcher.match(CssSelector.parse('[someAttr2][someAttr=someValue]')[0],
selectableCollector))
.toEqual(true);
expect(matched).toEqual([s1[0], 1, s2[0], 2]);

reset();
expect(matcher.match(CssSelector.parse('[someAttr2=someValue][someAttr]')[0],
selectableCollector))
.toEqual(true);
expect(matched).toEqual([s1[0], 1, s2[0], 2]);
});

it('should select by attr name only once if the value is from the DOM', () => {
Expand Down

0 comments on commit 9bad70b

Please sign in to comment.