mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibWeb: Make parsing of most CSS values case-insensitive
These are all valid: width: AUTO; height: 10PX; color: LiMeGrEeN;
This commit is contained in:
parent
d8cdf3f5e1
commit
57857cd8f6
Notes:
sideshowbarker
2024-07-19 06:40:21 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/57857cd8f69 Pull-request: https://github.com/SerenityOS/serenity/pull/2214 Reviewed-by: https://github.com/awesomekling
1 changed files with 7 additions and 5 deletions
|
@ -43,7 +43,7 @@ namespace Web {
|
||||||
|
|
||||||
static Optional<Color> parse_css_color(const StringView& view)
|
static Optional<Color> parse_css_color(const StringView& view)
|
||||||
{
|
{
|
||||||
auto color = Color::from_string(view);
|
auto color = Color::from_string(view.to_string().to_lowercase());
|
||||||
if (color.has_value())
|
if (color.has_value())
|
||||||
return color;
|
return color;
|
||||||
|
|
||||||
|
@ -128,7 +128,8 @@ static Optional<float> parse_number(const StringView& view)
|
||||||
if (view.ends_with('%'))
|
if (view.ends_with('%'))
|
||||||
return parse_number(view.substring_view(0, view.length() - 1));
|
return parse_number(view.substring_view(0, view.length() - 1));
|
||||||
|
|
||||||
if (view.ends_with("px"))
|
// FIXME: Maybe we should have "ends_with_ignoring_case()" ?
|
||||||
|
if (view.to_string().to_lowercase().ends_with("px"))
|
||||||
return parse_number(view.substring_view(0, view.length() - 2));
|
return parse_number(view.substring_view(0, view.length() - 2));
|
||||||
|
|
||||||
return try_parse_float(view);
|
return try_parse_float(view);
|
||||||
|
@ -142,11 +143,12 @@ NonnullRefPtr<StyleValue> parse_css_value(const StringView& string)
|
||||||
return PercentageStyleValue::create(number.value());
|
return PercentageStyleValue::create(number.value());
|
||||||
return LengthStyleValue::create(Length(number.value(), Length::Type::Absolute));
|
return LengthStyleValue::create(Length(number.value(), Length::Type::Absolute));
|
||||||
}
|
}
|
||||||
if (string == "inherit")
|
|
||||||
|
if (string.equals_ignoring_case("inherit"))
|
||||||
return InheritStyleValue::create();
|
return InheritStyleValue::create();
|
||||||
if (string == "initial")
|
if (string.equals_ignoring_case("initial"))
|
||||||
return InitialStyleValue::create();
|
return InitialStyleValue::create();
|
||||||
if (string == "auto")
|
if (string.equals_ignoring_case("auto"))
|
||||||
return LengthStyleValue::create(Length());
|
return LengthStyleValue::create(Length());
|
||||||
|
|
||||||
auto color = parse_css_color(string);
|
auto color = parse_css_color(string);
|
||||||
|
|
Loading…
Reference in a new issue