From 9bad70be5ee93424e64ade0acd62d901df998819 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 11 Jun 2015 11:35:02 -0700 Subject: [PATCH] fix(selector): select by attribute independent of value and order Closes #2513 --- .../src/render/dom/compiler/selector.ts | 5 +++++ .../test/render/dom/compiler/selector_spec.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/modules/angular2/src/render/dom/compiler/selector.ts b/modules/angular2/src/render/dom/compiler/selector.ts index 7f6c20013e..ddba38d9e0 100644 --- a/modules/angular2/src/render/dom/compiler/selector.ts +++ b/modules/angular2/src/render/dom/compiler/selector.ts @@ -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; } diff --git a/modules/angular2/test/render/dom/compiler/selector_spec.ts b/modules/angular2/test/render/dom/compiler/selector_spec.ts index 28ddd24d1c..de046b44bd 100644 --- a/modules/angular2/test/render/dom/compiler/selector_spec.ts +++ b/modules/angular2/test/render/dom/compiler/selector_spec.ts @@ -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', () => {