LibWeb: Make parsing of most CSS values case-insensitive

These are all valid:

width: AUTO;
height: 10PX;
color: LiMeGrEeN;
This commit is contained in:
Linus Groh 2020-05-13 17:18:16 +01:00 committed by Andreas Kling
parent d8cdf3f5e1
commit 57857cd8f6
Notes: sideshowbarker 2024-07-19 06:40:21 +09:00

View file

@ -43,7 +43,7 @@ namespace Web {
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())
return color;
@ -128,7 +128,8 @@ static Optional<float> parse_number(const StringView& view)
if (view.ends_with('%'))
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 try_parse_float(view);
@ -142,11 +143,12 @@ NonnullRefPtr<StyleValue> parse_css_value(const StringView& string)
return PercentageStyleValue::create(number.value());
return LengthStyleValue::create(Length(number.value(), Length::Type::Absolute));
}
if (string == "inherit")
if (string.equals_ignoring_case("inherit"))
return InheritStyleValue::create();
if (string == "initial")
if (string.equals_ignoring_case("initial"))
return InitialStyleValue::create();
if (string == "auto")
if (string.equals_ignoring_case("auto"))
return LengthStyleValue::create(Length());
auto color = parse_css_color(string);