webapi: remove "en" lang fallback

The "en" css fallback on document. I tested a number of pages, and pages with
no lang attribute return null on a `:lang('en')` query.
This commit is contained in:
Karl Seguin committed 2026-09-19 09:47:42 +08:00
1 parent ae928a91b1
commit 475ed9ae73
2 files changed
+31 -7

No files matched your search

@@ -99,3 +99,33 @@
testing.expectEqual('escaped', escaped.id);
}
</script>
<script id="lang">
{
// No lang attribute anywhere: nothing has a language, so nothing matches.
testing.expectEqual(0, document.querySelectorAll(':lang(en)').length);
const outer = document.createElement('div');
outer.innerHTML = '<p lang="en-AU"><span id="inherits"></span><span id="fr" lang="fr"></span><span id="unknown" lang=""></span></p><i id="none"></i>';
const p = outer.querySelector('p');
testing.expectTrue(p.matches(':lang(en)'));
testing.expectTrue(p.matches(':lang(en-au)'));
testing.expectFalse(p.matches(':lang(en-US)'));
testing.expectFalse(p.matches(':lang(e)'));
testing.expectTrue(outer.querySelector('#inherits').matches(':lang(en)'));
// The nearest lang attribute wins, and an empty one means unknown.
testing.expectFalse(outer.querySelector('#fr').matches(':lang(en)'));
testing.expectTrue(outer.querySelector('#fr').matches(':lang(fr)'));
testing.expectFalse(outer.querySelector('#unknown').matches(':lang(en)'));
testing.expectFalse(outer.querySelector('#none').matches(':lang(en)'));
testing.expectEqual(2, outer.querySelectorAll(':lang(en)').length);
document.body.appendChild(outer);
testing.expectEqual(2, document.querySelectorAll(':lang(en)').length);
outer.remove();
}
</script>
+1 -7
View File
@@ -659,10 +659,7 @@ fn matchesPseudoClass(el: *Node.Element, pseudo: Selector.PseudoClass, scope: *N
// Functional
.lang => |expected| {
if (expected.len == 0) return false;
// The element's language is the nearest ancestor-or-self lang
// attribute. Elements in a document with no declared language
// fall back to the UA default (en); detached subtrees have no
// language at all.
// The element's language is the nearest ancestor-or-self lang attribute.
const lang = blk: {
var current: ?*Node = node;
while (current) |cur| : (current = cur.parentNode()) {
@@ -672,9 +669,6 @@ fn matchesPseudoClass(el: *Node.Element, pseudo: Selector.PseudoClass, scope: *N
break :blk value;
}
},
.document => {
break :blk "en";
},
else => {},
}
}