Skip to content

Commit

Permalink
Handle tag names when used in conjunction with attribute selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Fuecks committed Oct 2, 2010
1 parent d7ed06c commit fa05d81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/soupselect.js
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions tests/soupselect.js
Expand Up @@ -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"]', []],
]);
});
Expand Down Expand Up @@ -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']],
]);
Expand All @@ -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]', []],
Expand Down

0 comments on commit fa05d81

Please sign in to comment.