mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +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:
parent
61f9b324c7
commit
7d2f631d4c
Notes:
github-actions[bot]
2025-11-18 16:24:24 +00:00
Author: https://github.com/AtkinsSJ
Commit: 7d2f631d4c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6859
Reviewed-by: https://github.com/gmta ✅
3 changed files with 27 additions and 18 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue