Browse files

Handle tag names when used in conjunction with attribute selectors

  • Loading branch information...
1 parent d7ed06c commit fa05d813b86f62aedafb8829f2bc0c8b1e0ae908 Harry Fuecks committed Oct 2, 2010
Showing with 10 additions and 8 deletions.
  1. +4 −2 lib/soupselect.js
  2. +6 −6 tests/soupselect.js
View
6 lib/soupselect.js
@@ -65,12 +65,14 @@ exports.select = function(dom, selector) {
var options = {};
options[attribute] = makeAttributeChecker(operator, attribute, value);
- if ( tag ) { options['tag_name'] = tag; }
-
var found = [];
currentContext.forEach(function(context) {
found = found.concat(domUtils.getElements(options, context));
});
+
+ if ( tag ) {
+ found = domUtils.getElements({ 'tag_name': tag }, found);
+ }
currentContext = found
View
12 tests/soupselect.js
@@ -245,9 +245,9 @@ exports.attributeSelectors = {
assertSelectMultiple(test, dom, [
['[href$=".css"]', ['l1']],
['link[href$=".css"]', ['l1']],
- // ['link[id$="1"]', ['l1']],
+ ['link[id$="1"]', ['l1']],
['[id$="1"]', ['l1', 'p1', 'header1']],
- // ['div[id$="1"]', []],
+ ['div[id$="1"]', []],
['[id$="noending"]', []],
]);
});
@@ -278,8 +278,8 @@ exports.attributeSelectors = {
['[id*="noending"]', []],
// New for this test
['[href*="."]', ['bob', 'me', 'l1']],
- // ['a[href*="."]', ['bob', 'me']],
- // ['link[href*="."]', ['l1']],
+ ['a[href*="."]', ['bob', 'me']],
+ ['link[href*="."]', ['l1']],
// ['div[id*="n"]', ['main', 'inner']],
['div[id*="nn"]', ['inner']],
]);
@@ -303,8 +303,8 @@ exports.attributeSelectors = {
runTest(test, function(dom) {
assertSelectMultiple(test, dom, [
['[rel]', ['l1', 'bob', 'me']],
- // ['link[rel]', ['l1']],
- // ['a[rel]', ['bob', 'me']],
+ ['link[rel]', ['l1']],
+ ['a[rel]', ['bob', 'me']],
['[lang]', ['lang-en', 'lang-en-gb', 'lang-en-us', 'lang-fr']],
['p[class]', ['p1', 'pmulti']],
['[blah]', []],

0 comments on commit fa05d81

Please sign in to comment.