srctree

Robin Linden parent 5dfc8ff1 b9e49bdb
engine: Don't try to parse encoded responses as css

inlinesplit
engine/engine.cpp added: 40, removed: 2, total 38
@@ -111,6 +111,11 @@ void Engine::on_navigation_success() {
return {};
}
 
if (auto encoding = style_data.headers.get("Content-Encoding")) {
spdlog::warn("Got unsupported encoding '{}', skipping stylesheet '{}'", *encoding, stylesheet_url.uri);
return {};
}
 
return css::parse(style_data.body);
}));
}
 
engine/engine_test.cpp added: 40, removed: 2, total 38
@@ -149,5 +149,38 @@ int main() {
expect_eq(e.layout()->get_property<css::PropertyId::Display>(), style::DisplayValue::Inline);
});
 
etest::test("stylesheet link, unsupported Content-Encoding", [] {
protocol::Headers css_response_headers;
css_response_headers.add({"Content-Encoding", "really-borked-content-type"});
 
std::map<std::string, Response> responses{
{
"hax://example.com"s,
Response{
.err = Error::Ok,
.status_line = {.status_code = 200},
.body{"<html><head><link rel=stylesheet href=lol.css /></head></html>"},
},
},
{
"hax://example.com/lol.css"s,
Response{
.err = Error::Ok,
.status_line = {.status_code = 200},
.headers{std::move(css_response_headers)},
.body{"p { font-size: 123em; }"},
},
},
};
engine::Engine e{std::make_unique<FakeProtocolHandler>(std::move(responses))};
e.navigate(uri::Uri::parse("hax://example.com"));
expect(std::ranges::find(e.stylesheet(),
css::Rule{
.selectors{"p"},
.declarations{{css::PropertyId::FontSize, "123em"}},
})
== end(e.stylesheet()));
});
 
return etest::run_all_tests();
}