Forráskód Böngészése

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"
Andreas Kling 5 éve
szülő
commit
df16c9676b
1 módosított fájl, 4 hozzáadás és 7 törlés
  1. 4 7
      Libraries/LibHTML/Parser/CSSParser.cpp

+ 4 - 7
Libraries/LibHTML/Parser/CSSParser.cpp

@@ -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")