mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
LibWeb/CSS: Handle whitespace better in font-language-override strings
The rules for strings here are: - 4 ASCII characters long - Shorter ones are right-padded with spaces before use - Trailing whitespace is always removed when serializing We previously always padded them during parsing, which was incorrect. This commit flips it around so we trim trailing whitespace when parsing. We don't yet actually use this property's value for anything. Once we do so, maybe we'll care more about them being stored as 4 characters always, but for now this avoids us needing a special step during computation.
This commit is contained in:
committed by
Jelle Raaijmakers
parent
61f9b324c7
commit
7d2f631d4c
Notes:
github-actions[bot]
2025-11-18 16:24:24 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/7d2f631d4c4 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6859 Reviewed-by: https://github.com/gmta ✅
@@ -2880,7 +2880,7 @@ RefPtr<StyleValue const> Parser::parse_font_language_override_value(TokenStream<
|
||||
{
|
||||
// https://drafts.csswg.org/css-fonts/#propdef-font-language-override
|
||||
// This is `normal | <string>` but with the constraint that the string has to be 4 characters long:
|
||||
// Shorter strings are right-padded with spaces, and longer strings are invalid.
|
||||
// Shorter strings are right-padded with spaces before use, and longer strings are invalid.
|
||||
|
||||
if (auto normal = parse_all_as_single_keyword_value(tokens, Keyword::Normal))
|
||||
return normal;
|
||||
@@ -2927,9 +2927,20 @@ RefPtr<StyleValue const> Parser::parse_font_language_override_value(TokenStream<
|
||||
});
|
||||
return nullptr;
|
||||
}
|
||||
// We're expected to always serialize without any trailing spaces, so remove them now for convenience.
|
||||
auto trimmed = string_value.bytes_as_string_view().trim_whitespace(TrimMode::Right);
|
||||
if (trimmed.is_empty()) {
|
||||
ErrorReporter::the().report(InvalidPropertyError {
|
||||
.rule_name = "style"_fly_string,
|
||||
.property_name = "font-language-override"_fly_string,
|
||||
.value_string = tokens.dump_string(),
|
||||
.description = MUST(String::formatted("<string> value \"{}\" is only whitespace", string_value)),
|
||||
});
|
||||
return nullptr;
|
||||
}
|
||||
transaction.commit();
|
||||
if (length < 4)
|
||||
return StringStyleValue::create(MUST(String::formatted("{:<4}", string_value)));
|
||||
if (trimmed != string_value.bytes_as_string_view())
|
||||
return StringStyleValue::create(FlyString::from_utf8_without_validation(trimmed.bytes()));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@ Harness status: OK
|
||||
|
||||
Found 5 tests
|
||||
|
||||
1 Pass
|
||||
4 Fail
|
||||
5 Pass
|
||||
Pass Property font-language-override value 'normal'
|
||||
Fail Property font-language-override value '"KSW"'
|
||||
Fail Property font-language-override value '"ENG "'
|
||||
Fail Property font-language-override value '"en "'
|
||||
Fail Property font-language-override value '" en "'
|
||||
Pass Property font-language-override value '"KSW"'
|
||||
Pass Property font-language-override value '"ENG "'
|
||||
Pass Property font-language-override value '"en "'
|
||||
Pass Property font-language-override value '" en "'
|
||||
@@ -2,14 +2,13 @@ Harness status: OK
|
||||
|
||||
Found 9 tests
|
||||
|
||||
2 Pass
|
||||
7 Fail
|
||||
9 Pass
|
||||
Pass e.style['font-language-override'] = "normal" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"KSW\"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"KSW\"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"APPH\"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"ENG \"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"ksw\"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"tr\"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"en \"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\" en \"" should set the property value
|
||||
Fail e.style['font-language-override'] = "\"1 %\"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"ENG \"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"ksw\"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"tr\"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"en \"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\" en \"" should set the property value
|
||||
Pass e.style['font-language-override'] = "\"1 %\"" should set the property value
|
||||
Reference in New Issue
Block a user