diff --git a/CHANGELOG b/CHANGELOG index bc3d685..cb7fe5e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Ensure no comment nodes are returned in Selector queries (IE improperly returns comment nodes on getElementsByTagName("*")). Change Element#descendants to use Element#getElementsBySelector in order to avoid this issue. Closes #10220. [Jeff Gobel, Andrew Dupont] + * Re-enable the XPath approach in Selector for Safari 3. Falls back to the non-XPath version when it sees a problematic token. [Andrew Dupont] * Fix a bug in the IE-specific Element#descendantOf logic. [Nicholas, Andrew Dupont] diff --git a/src/dom.js b/src/dom.js index a46f841..67f1846 100644 --- a/src/dom.js +++ b/src/dom.js @@ -181,7 +181,7 @@ Element.Methods = { }, descendants: function(element) { - return $A($(element).getElementsByTagName('*')).each(Element.extend); + return $(element).getElementsBySelector("*"); }, firstDescendant: function(element) { diff --git a/src/selector.js b/src/selector.js index d763c1d..f49d539 100644 --- a/src/selector.js +++ b/src/selector.js @@ -647,6 +647,16 @@ Object.extend(Selector, { } }); +if (Prototype.Browser.IE) { + // IE returns comment nodes on getElementsByTagName("*"). + // Filter them out. + Selector.handlers.concat = function(a, b) { + for (var i = 0, node; node = b[i]; i++) + if (node.tagName !== "!") a.push(node); + return a; + }; +} + function $$() { return Selector.findChildElements(document, $A(arguments)); } diff --git a/test/unit/dom.html b/test/unit/dom.html index 8f7dcc6..3154ec9 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -189,6 +189,7 @@