LibWeb: Use Content-Type header to set document encoding

Co-authored-by: Shannon Booth <shannon@serenityos.org>
This commit is contained in:
Gingeh 2024-10-20 19:39:50 +11:00 committed by Andrew Kaster
parent 1096b64936
commit 8e342e3e23
Notes: github-actions[bot] 2024-10-23 17:32:00 +00:00
3 changed files with 7 additions and 6 deletions

View file

@ -4373,11 +4373,11 @@ JS::NonnullGCPtr<HTMLParser> HTMLParser::create_for_scripting(DOM::Document& doc
return document.heap().allocate_without_realm<HTMLParser>(document);
}
JS::NonnullGCPtr<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input)
JS::NonnullGCPtr<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional<MimeSniff::MimeType> maybe_mime_type)
{
if (document.has_encoding())
return document.heap().allocate_without_realm<HTMLParser>(document, input, document.encoding().value().to_byte_string());
auto encoding = run_encoding_sniffing_algorithm(document, input);
auto encoding = run_encoding_sniffing_algorithm(document, input, maybe_mime_type);
dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding);
return document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
}