fix(selector): select by attribute independent of value and order

Closes #2513
This commit is contained in:
Tobias Bosch 2015-06-11 11:35:02 -07:00
parent 5bfcca2d5b
commit 9bad70be5e
2 changed files with 23 additions and 0 deletions

View File

@ -285,6 +285,11 @@ export class SelectorMatcher {
result; result;
var partialValuesMap = MapWrapper.get(this._attrValuePartialMap, attrName); 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 = result =
this._matchPartial(partialValuesMap, attrValue, cssSelector, matchedCallback) || result; this._matchPartial(partialValuesMap, attrValue, cssSelector, matchedCallback) || result;
} }

View File

@ -68,6 +68,24 @@ export function main() {
expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector)) expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector))
.toEqual(true); .toEqual(true);
expect(matched).toEqual([s1[0], 1, s2[0], 2]); 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', () => { it('should select by attr name only once if the value is from the DOM', () => {