Skip to content

Commit 1206dd2

Browse files
committed
LibWeb: Make parse_html_length() accept floating point numbers
This makes stuff like <img width="12.5"> work. This code is not great, so I've left a FIXME about improving it.
1 parent 196a3eb commit 1206dd2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,9 +4976,22 @@ RefPtr<CSS::Supports> parse_css_supports(CSS::ParsingContext const& context, Str
49764976

49774977
RefPtr<CSS::StyleValue> parse_html_length(DOM::Document const& document, StringView string)
49784978
{
4979+
if (string.is_null())
4980+
return nullptr;
4981+
49794982
auto integer = string.to_int();
49804983
if (integer.has_value())
49814984
return CSS::LengthStyleValue::create(CSS::Length::make_px(integer.value()));
4985+
4986+
{
4987+
// FIXME: This is both ad-hoc and inefficient (note the String allocation!)
4988+
String string_copy(string);
4989+
char const* endptr = nullptr;
4990+
auto double_value = strtod(string_copy.characters(), const_cast<char**>(&endptr));
4991+
if (endptr != string_copy.characters())
4992+
return CSS::LengthStyleValue::create(CSS::Length::make_px(double_value));
4993+
}
4994+
49824995
return parse_css_value(CSS::ParsingContext(document), string);
49834996
}
49844997

0 commit comments

Comments
 (0)