Don't count <img> elements with both name and id twice in document's named getter (#37455)

A document's named getter collects elements with either matching name or
id's (varies per element type) and returns them .

We implement this the following way:
* Create an iterator with elements whose `name` attribute matches
* Create an iterator with elements whose `id` attribute matches
* Concatenate both

The spec then asks us if there is more than one element in the list,
which we implement by checking whether the iterator returns `None` after
we get the first element. However, the same element can appear in both
iterators if it is a `img` element and both it's name and id attribute
match. Therefore, we need to check if there are more elements *which are
not equal to the first one*.

Testing: New web platform tests pass

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-06-15 20:54:53 +02:00 committed by GitHub
parent ae20cdbdc9
commit 9d10e41a1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 21 deletions

View file

@ -122,7 +122,7 @@ impl XMLDocumentMethods<crate::DomTypeHolder> for XMLDocument {
}
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
fn NamedGetter(&self, name: DOMString) -> Option<NamedPropertyValue> {
self.upcast::<Document>().NamedGetter(name)
fn NamedGetter(&self, name: DOMString, can_gc: CanGc) -> Option<NamedPropertyValue> {
self.upcast::<Document>().NamedGetter(name, can_gc)
}
}