From c67fe0b2f34231b35e9c483abce7778003997468 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 18 Jan 2008 04:52:38 +0000 Subject: [PATCH] Fixed selector parsing so that "#foo [bar=baz]" is treated the same way as "#foo *[bar=baz]". Closes #10734. [jlukas, kangax, Andrew Dupont] --- CHANGELOG | 2 ++ src/selector.js | 16 +++++++++------- test/unit/selector.html | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 60aeb23..bf01d76 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed selector parsing so that "#foo [bar=baz]" is treated the same way as "#foo *[bar=baz]". Closes #10734. [jlukas, kangax, Andrew Dupont] + * Fix Element#descendantOf logic in IE. Closes #10413. [martymix, kamil.szot] * Fix missing "var" in Element#insert. Closes #10838. [Lantash] diff --git a/src/selector.js b/src/selector.js index 5453f15..fd7da25 100644 --- a/src/selector.js +++ b/src/selector.js @@ -241,13 +241,13 @@ Object.extend(Selector, { }, criteria: { - tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', - className: 'n = h.className(n, r, "#{1}", c); c = false;', - id: 'n = h.id(n, r, "#{1}", c); c = false;', - attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', + tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', + className: 'n = h.className(n, r, "#{1}", c); c = false;', + id: 'n = h.id(n, r, "#{1}", c); c = false;', + attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;', attr: function(m) { m[3] = (m[5] || m[6]); - return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); + return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m); }, pseudo: function(m) { if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); @@ -457,16 +457,18 @@ Object.extend(Selector, { return results; }, - attrPresence: function(nodes, root, attr) { + attrPresence: function(nodes, root, attr, combinator) { if (!nodes) nodes = root.getElementsByTagName("*"); + if (nodes && combinator) nodes = this[combinator](nodes); var results = []; for (var i = 0, node; node = nodes[i]; i++) if (Element.hasAttribute(node, attr)) results.push(node); return results; }, - attr: function(nodes, root, attr, value, operator) { + attr: function(nodes, root, attr, value, operator, combinator) { if (!nodes) nodes = root.getElementsByTagName("*"); + if (nodes && combinator) nodes = this[combinator](nodes); var handler = Selector.operators[operator], results = []; for (var i = 0, node; node = nodes[i]; i++) { var nodeValue = Element.readAttribute(node, attr); diff --git a/test/unit/selector.html b/test/unit/selector.html index 3c1383d..6939e77 100644 --- a/test/unit/selector.html +++ b/test/unit/selector.html @@ -184,6 +184,8 @@ assertEnumEqual($('checked_radio', 'unchecked_radio'), $$('[type=radio]')); assertEnumEqual($$('*[type=checkbox]'), $$('[type=checkbox]')); assertEnumEqual($('with_title', 'commaParent'), $$('[title]')); + assertEnumEqual($$('#troubleForm *[type=radio]'), $$('#troubleForm [type=radio]')); + assertEnumEqual($$('#troubleForm *[type]'), $$('#troubleForm [type]')); }}, testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) {