summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Loader
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-05-12 10:47:12 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-18 21:02:07 +0200
commitf8082797694290c09fa32b2480e4eecde452c372 (patch)
tree19da92250f2c4d1bbbc2f4a997b1ef1a45d9128f /Userland/Libraries/LibWeb/Loader
parent67a9ebc8176e6dff4c3af3bc26ef3de829d87286 (diff)
downloadserenity-f8082797694290c09fa32b2480e4eecde452c372.zip
LibWeb: Implement encoding sniffing algorithm
This patch implements the HTML specification's "encoding sniffing algorithm", which is used when no encoding can be obtained from the Content-Type header (either because it doesn't contain a charset=...) value or the file has not been opened via HTTP (as with local files). It also modifies the creator of the HTMLDocumentParser to use the new HTMLDocumentParser::create_with_uncertain_encoding static method, which runs the encoding sniffing algorithm before instantiating the parser. This now allows us to load local HTML pages (or remote pages without a charset specified in the 'Content-Type' header) with a non-UTF-8 encoding such as 'windows-1252'. This would previously crash the browser. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Loader')
-rw-r--r--Userland/Libraries/LibWeb/Loader/FrameLoader.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
index adaba8905e..55a251deee 100644
--- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp
@@ -113,8 +113,8 @@ bool FrameLoader::parse_document(DOM::Document& document, const ByteBuffer& data
{
auto& mime_type = document.content_type();
if (mime_type == "text/html" || mime_type == "image/svg+xml") {
- HTML::HTMLDocumentParser parser(document, data, document.encoding_or_default());
- parser.run(document.url());
+ auto parser = HTML::HTMLDocumentParser::create_with_uncertain_encoding(document, data);
+ parser->run(document.url());
return true;
}
if (mime_type.starts_with("image/"))