1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibHTML: Tolerate "px" suffix on CSS lengths

We only support "px" units (and "auto") but we shouldn't choke just
because someone actually says "10px" instead of just "10"
This commit is contained in:
Andreas Kling 2019-11-18 12:15:23 +01:00
parent 00d171e4d6
commit df16c9676b

View file

@ -25,13 +25,10 @@ static Optional<Color> parse_css_color(const StringView& view)
NonnullRefPtr<StyleValue> parse_css_value(const StringView& view) NonnullRefPtr<StyleValue> parse_css_value(const StringView& view)
{ {
String string(view); String string(view);
bool ok; char* endptr = nullptr;
int as_int = string.to_int(ok); long value = strtol(String(view).characters(), &endptr, 10);
if (ok) if (endptr && ((!*endptr) || (endptr[0] == 'p' && endptr[1] == 'x' && endptr[2] == '\0')))
return LengthStyleValue::create(Length(as_int, Length::Type::Absolute)); return LengthStyleValue::create(Length(value, Length::Type::Absolute));
unsigned as_uint = string.to_uint(ok);
if (ok)
return LengthStyleValue::create(Length(as_uint, Length::Type::Absolute));
if (string == "inherit") if (string == "inherit")
return InheritStyleValue::create(); return InheritStyleValue::create();
if (string == "initial") if (string == "initial")