diff --git a/CHANGELOG b/CHANGELOG index 931fdf4..b2d5c91 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Prevent an error being thrown by $$ when #id does not exist in $$("div #id"). Closes #8325. [Tobie Langel, ecke] + * Make Prototype.ScriptFragment behave when including Prototype inline. [Christophe Porteneuve] * Deprecate Position (kept for backwards compatibility). Add Element#cumulativeOffset, Element#positionedOffset, Element#absolutize, Element#relativize, Element#cumulativeScrollOffset, Element#getOffsetParent, Element#viewportOffset and Element#clonePosition. [Christophe Porteneuve] diff --git a/src/selector.js b/src/selector.js index 37b68eb..d98d099 100644 --- a/src/selector.js +++ b/src/selector.js @@ -339,7 +339,8 @@ Object.extend(Selector, { id: function(nodes, root, id, combinator) { var targetNode = $(id), h = Selector.handlers; - if (!nodes && root == document) return targetNode ? [targetNode] : []; + if (!targetNode) return []; + if (!nodes && root == document) return [targetNode]; if (nodes) { if (combinator) { if (combinator == 'child') { diff --git a/test/unit/selector.html b/test/unit/selector.html index d43474a..baa6ba2 100644 --- a/test/unit/selector.html +++ b/test/unit/selector.html @@ -219,6 +219,7 @@ assertEnumEqual($('level2_1', 'level2_2'), $$('#level1>span')); assertEnumEqual($('level2_1', 'level2_2'), $$('#level1 > span')); assertEnumEqual($('level3_1', 'level3_2'), $$('#level2_1 > *')); + assertEnumEqual([], $$('div > #nonexistent')); $RunBenchmarks && wait(500, function() { benchmark(function() { $$('#level1 > span') }, 1000); });