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
commit df16c9676b
Notes: sideshowbarker 2024-07-19 11:09:52 +09:00

View file

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