Commit 61ef91a2 authored by Timothy Gu's avatar Timothy Gu Committed by Commit Bot

Fix ContainerNode::getElementById() with empty ID differently

We previously tried to fix this in
Ia65024efef9e5ef54d9db233590a17b372282ed1, but it appears that we were
overly optimistic. This commit puts in place a more conversative fix
that does not change anything other than
ContainerNode::getElementById(). Note that this is a different function
from Document::getElementById().

Instead of filtering out the empty ID in AttributeChanged(), put an
empty-string special case in ContainerNode::getElementById(), similar to
what is currently done for Document::getElementById(). This fixes the
original bug without implicating other parts of Blink.

Fixed: 1068580
Change-Id: Ib54bbc444babd9cbae4409cdecc09640bcb757c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146787Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Timothy Gu <timothygu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758647}
parent 4568475c
......@@ -1551,6 +1551,12 @@ RadioNodeList* ContainerNode::GetRadioNodeList(const AtomicString& name,
}
Element* ContainerNode::getElementById(const AtomicString& id) const {
// According to https://dom.spec.whatwg.org/#concept-id, empty IDs are
// treated as equivalent to the lack of an id attribute.
if (id.IsEmpty()) {
return nullptr;
}
if (IsInTreeScope()) {
// Fast path if we are in a tree scope: call getElementById() on tree scope
// and check if the matching element is in our subtree.
......
This is a testharness.js-based test.
PASS The method must exist
PASS It must return null when there are no matches
PASS It must return the first element when there are matches
FAIL Empty string ID values assert_equals: Even if there is an element with an empty-string ID attribute, it must not be returned expected null but got Element node <div id=""></div>
PASS It must return the first element when there are matches, using a template
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment