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

LibWeb/MimeSniff: Add non-standard text or binary context sniffing

This is used in cases where the spec expects us to only run the
"rules for distinguishing if a resource is a text or binary" algo.
This commit is contained in:
Kemal Zebari 2024-02-01 16:32:52 -08:00 committed by Tim Flynn
parent 8a974ca91a
commit 8e5410347b
3 changed files with 16 additions and 0 deletions

View file

@ -320,3 +320,13 @@ TEST_CASE(determine_computed_mime_type_in_a_font_context)
EXPECT_EQ(mime_type, computed_mime_type.essence());
}
TEST_CASE(determine_computed_mime_type_given_text_or_binary_context)
{
auto supplied_type = MUST(Web::MimeSniff::MimeType::create("text"_string, "plain"_string));
auto computed_mime_type = MUST(Web::MimeSniff::Resource::sniff("\x00"sv.bytes(), Web::MimeSniff::SniffingConfiguration {
.sniffing_context = Web::MimeSniff::SniffingContext::TextOrBinary,
.supplied_type = supplied_type,
}));
EXPECT_EQ("application/octet-stream"sv, MUST(computed_mime_type.serialized()));
}