Bug 144429 - LiveNodeList may unexpectedly return an element for empty string
Summary: LiveNodeList may unexpectedly return an element for empty string
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-29 19:08 PDT by Joseph Pecoraro
Modified: 2015-04-29 20:29 PDT (History)
5 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (3.56 KB, patch)
2015-04-29 19:38 PDT, Joseph Pecoraro
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-04-29 19:08:45 PDT
* SUMMARY
LiveNodeList may unexpectedly return an element for empty string.

* TEST
<body>
<script>
var container = document.createElement("div");
var div = document.createElement("div");
div.id = "";
container.appendChild(div);
var div2 = document.createElement("div");
div2.id = "foo";
container.appendChild(div2);
var list = container.getElementsByTagName("div");
alert(list[""]); // expected: undefined, actual: div#foo
alert(list["foo"]); // expected: div#foo, actual: div#foo
</script>

* NOTES
- Firefox and Chrome both produce the expected results.
Comment 1 Joseph Pecoraro 2015-04-29 19:38:21 PDT
Created attachment 252029 [details]
[PATCH] Proposed Fix
Comment 2 Darin Adler 2015-04-29 19:41:52 PDT
Comment on attachment 252029 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=252029&action=review

> Source/WebCore/dom/LiveNodeList.cpp:57
> +    if (elementId.isEmpty())
> +        return nullptr;

You could put this check after the rootNode.inDocument() block; no need to do even this small amount of extra work in the common case.
Comment 3 Joseph Pecoraro 2015-04-29 20:29:44 PDT
http://trac.webkit.org/changeset/183612