LibWeb: Don't advertise the empty string as HTMLCollection property name

This fixes wpt/dom/collections/HTMLCollection-empty-name.html
This commit is contained in:
Andreas Kling 2024-05-27 10:47:19 +02:00
parent 8988dce93d
commit e7febd347b
Notes: sideshowbarker 2024-07-17 04:09:56 +09:00
3 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Empty string in collection: false
'haxx' in collection: true

View file

@ -0,0 +1,10 @@
<script src="../include.js"></script>
<div id></div>
<div id=haxx></div>
<script>
test(() => {
var c = document.getElementsByTagName("*");
println("Empty string in collection: " + ("" in c));
println("'haxx' in collection: " + ("haxx" in c));
});
</script>

View file

@ -135,7 +135,7 @@ Vector<FlyString> HTMLCollection::supported_property_names() const
for (auto const& element : m_cached_elements) {
// 1. If element has an ID which is not in result, append elements ID to result.
if (auto const& id = element->id(); id.has_value()) {
if (!result.contains_slow(id.value()))
if (!id.value().is_empty() && !result.contains_slow(id.value()))
result.append(id.value());
}