From f20822e29338c4febf2e5d2d555972daf03c4bf0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 2 Nov 2024 03:48:19 +1300 Subject: [PATCH] LibWeb: Handle language attributes without a '-' Where we would previously index out of bounds. --- .../the-lang-attribute-008.txt | 11 +++++ .../the-lang-attribute-009.txt | 11 +++++ .../the-lang-attribute-010.txt | 11 +++++ .../the-lang-attribute-008.html | 41 ++++++++++++++++++ .../the-lang-attribute-009.html | 41 ++++++++++++++++++ .../the-lang-attribute-010.html | 42 +++++++++++++++++++ .../Libraries/LibWeb/CSS/SelectorEngine.cpp | 2 +- 7 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.html diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.txt new file mode 100644 index 00000000000..149f17722f0 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.txt @@ -0,0 +1,11 @@ +Summary + +Harness status: OK + +Rerun + +Found 1 tests + +1 Pass +Details +Result Test Name MessagePass If an element contains a lang attribute with an empty value, the value of a lang attribute higher up the document tree will no longer be applied to the content of that element. \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.txt new file mode 100644 index 00000000000..cc35505facf --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.txt @@ -0,0 +1,11 @@ +Summary + +Harness status: OK + +Rerun + +Found 1 tests + +1 Pass +Details +Result Test Name MessagePass If the HTTP header contains a language declaration but the html element uses an empty lang value, the UA will not recognize the language declared in the HTTP header. \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.txt new file mode 100644 index 00000000000..541b49348ae --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.txt @@ -0,0 +1,11 @@ +Summary + +Harness status: OK + +Rerun + +Found 1 tests + +1 Pass +Details +Result Test Name MessagePass If the meta Content-Language element contains a language declaration but the html element uses an empty lang value, the UA will not recognize the language declared in the meta Content-Language element. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.html new file mode 100644 index 00000000000..9aa0a9c387e --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-008.html @@ -0,0 +1,41 @@ + + + + +lang="..." vs lang="" + + + + + + + + + + + +
 
+

This test failed because it relies on :lang for results, but :lang is not supported by this browser.

+ + + + + +
+ + + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.html new file mode 100644 index 00000000000..6db816e6b71 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-009.html @@ -0,0 +1,41 @@ + + + + +lang="" vs HTTP + + + + + + + + + + + +
 
+

This test failed because it relies on :lang for results, but :lang is not supported by this browser.

+ + + + + +
+ + + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.html new file mode 100644 index 00000000000..40cf76da21b --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/the-lang-attribute-010.html @@ -0,0 +1,42 @@ + + + + + +lang="" vs meta Content-Language + + + + + + + + + + + +
 
+

This test failed because it relies on :lang for results, but :lang is not supported by this browser.

+ + + + + +
+ + + diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index 9bf1efbc1cf..e5aaf79697f 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -72,7 +72,7 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector if (!element_language.contains('-') && Infra::is_ascii_case_insensitive_match(element_language, language)) return true; auto parts = element_language.split_limit('-', 2).release_value_but_fixme_should_propagate_errors(); - if (Infra::is_ascii_case_insensitive_match(parts[0], language)) + if (!parts.is_empty() && Infra::is_ascii_case_insensitive_match(parts[0], language)) return true; } return false;