Skip to content

Commit

Permalink
Honor “lang” attribute in no namespace only on HTML and SVG elements
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263655

Reviewed by Ryosuke Niwa.

https://github.com/whatwg/html/pull/9882/files added the phrase “or an
element in the SVG namespace” in the following HTML spec text:

> To determine the language of a node, user agents must use the first
appropriate step in the following list:
> …
> - If the node is an HTML element or an element in the SVG namespace,
    and it has a lang in no namespace attribute set: Use the value of
    that attribute.

And that updated spec text is now part of the HTML standard, at
https://html.spec.whatwg.org/#the-lang-and-xml:lang-attributes:svg-namespace

Gecko has already had that behavior implemented for quite a while, and
Blink was recently updated to implement it as well.

So this change fully aligns WebKit with that updated spec text, and with
the current behavior in Gecko and Blink. However, this change does that
by updating the code to *restrict* the “lang” attribute in no namespace
to *only* being honored on HTML and SVG elements.

Otherwise, without this code change, WebKit honors the “lang” attribute
in no namespace regardless of what element it’s specified on (that is,
not just for HTML elements and SVG elements) — which breaks conformance
with the spec, and breaks interoperability with Gecko and Blink.

* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/lang-attribute.window-expected.txt:
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::attributeChanged):

Canonical link: https://commits.webkit.org/273726@main
  • Loading branch information
sideshowbarker authored and rniwa committed Jan 30, 2024
1 parent 2fc8377 commit 6599021
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL unnamespaced lang attribute only works on elements in the HTML namespace assert_true: child matches en-CA expected true got false
PASS unnamespaced lang attribute only works on elements in the HTML namespace

2 changes: 1 addition & 1 deletion Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ void Element::attributeChanged(const QualifiedName& name, const AtomString& oldV
case AttributeNames::XML::langAttr:
case AttributeNames::langAttr: {
if (name == HTMLNames::langAttr)
setHasLangAttr(!newValue.isNull());
setHasLangAttr(!newValue.isNull() && (isHTMLElement() || isSVGElement()));
else
setHasXMLLangAttr(!newValue.isNull());
Ref document = this->document();
Expand Down

0 comments on commit 6599021

Please sign in to comment.