Skip to content

Truly independent web browser

LibWeb: Inherit a same-origin parent's encoding when sniffing

Andreas Klinge415a9a65582
diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cpp
index d6b5ab164a1..327edc31689 100644
--- a/Libraries/LibWeb/DOM/DocumentLoading.cpp
+++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp
@@ -156,7 +156,8 @@ static WebIDL::ExceptionOr<GC::Ref<DOM::Document>> load_html_document(HTML::Navi
// document's relevant global object to have the parser to process the implied EOF character, which eventually
// causes a load event to be fired.
else {
- auto parser = HTML::IncrementalDocumentParser::create(document, *navigation_params.response);
+ auto container_document = navigation_params.navigable ? navigation_params.navigable->container_document() : nullptr;
+ auto parser = HTML::IncrementalDocumentParser::create(document, *navigation_params.response, container_document);
parser->set_allow_declarative_shadow_roots(HTML::HTMLParser::AllowDeclarativeShadowRoots::Yes);
parser->start();
}
@@ -280,8 +281,9 @@ static WebIDL::ExceptionOr<GC::Ref<DOM::Document>> load_text_document(HTML::Navi
// document's relevant global object to have the parser to process the implied EOF character, which eventually causes a
// load event to be fired.
// FIXME: Parse as we receive the document data, instead of waiting for the whole document to be fetched first.
- auto process_body = GC::create_function(GC::Heap::the(), [document, url = navigation_params.response->url().value(), response_header_list = navigation_params.response->header_list(), mime = type](ByteBuffer data) {
- auto [encoding, confidence] = HTML::run_encoding_sniffing_algorithm(document, data, mime);
+ auto container_document = navigation_params.navigable ? navigation_params.navigable->container_document() : nullptr;
+ auto process_body = GC::create_function(GC::Heap::the(), [document, container_document, url = navigation_params.response->url().value(), response_header_list = navigation_params.response->header_list(), mime = type](ByteBuffer data) {
+ auto [encoding, confidence] = HTML::run_encoding_sniffing_algorithm(document, data, mime, container_document);
dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding);
auto run_text_parser = [document, data = move(data), url, response_header_list, encoding = move(encoding)] {
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.cpp b/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.cpp
index beac061dd54..9cffbae2c2d 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.cpp
@@ -596,7 +596,7 @@ ByteString extract_tld_hint(URL::URL const& url)
}
// https://html.spec.whatwg.org/multipage/parsing.html#determining-the-character-encoding
-EncodingSniffingResult run_encoding_sniffing_algorithm(DOM::Document& document, ReadonlyBytes input, Optional<MimeSniff::MimeType> maybe_mime_type)
+EncodingSniffingResult run_encoding_sniffing_algorithm(DOM::Document& document, ReadonlyBytes input, Optional<MimeSniff::MimeType> maybe_mime_type, GC::Ptr<DOM::Document> loading_container_document)
{
// 1. If the result of BOM sniffing is an encoding, return that encoding with confidence certain.
auto bom = run_bom_sniff(input);
@@ -626,10 +626,18 @@ EncodingSniffingResult run_encoding_sniffing_algorithm(DOM::Document& document,
if (prescan.has_value())
return { prescan.release_value(), EncodingConfidence::Tentative };
- // 6. FIXME: If the HTML parser for which this algorithm is being run is associated with a Document d whose container document is non-null, then:
- // 1. Let parentDocument be d's container document.
- // 2. If parentDocument's origin is same origin with d's origin and parentDocument's character encoding is not UTF-16BE/LE, then return parentDocument's character
- // encoding, with the confidence tentative.
+ // 6. If the HTML parser for which this algorithm is being run is associated with a Document d whose container document is non-null, then:
+ auto parent_document = loading_container_document ? loading_container_document : document.container_document();
+ if (parent_document) {
+ // 1. Let parentDocument be d's container document.
+ // 2. If parentDocument's origin is same origin with d's origin and parentDocument's character encoding is not UTF-16BE/LE, then return parentDocument's character
+ // encoding, with the confidence tentative.
+ if (parent_document->origin().is_same_origin(document.origin())) {
+ auto parent_encoding = parent_document->character_set().to_byte_string();
+ if (!parent_encoding.is_one_of_ignoring_ascii_case("UTF-16BE"sv, "UTF-16LE"sv))
+ return { move(parent_encoding), EncodingConfidence::Tentative };
+ }
+ }
// 7. Otherwise, if the user agent has information on the likely encoding for this page, e.g. based on the encoding of the page when it was last visited, then return
// that encoding, with the confidence tentative.
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.h b/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.h
index 6309aa2ffd4..e93909b40f1 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.h
+++ b/Libraries/LibWeb/HTML/Parser/HTMLEncodingDetection.h
@@ -37,7 +37,10 @@ Optional<ByteString> run_bom_sniff(ReadonlyBytes input);
// an absent/empty TLD as equivalent to ".com".
ByteString extract_tld_hint(URL::URL const&);
+// NB: A document that is being loaded by a navigation has no node navigable until it is activated, which can happen
+// after its parser starts. Pass the container document of the navigable that the document is being loaded into as
+// loading_container_document in that case.
EncodingSniffingResult run_encoding_sniffing_algorithm(DOM::Document&, ReadonlyBytes input,
- Optional<MimeSniff::MimeType> maybe_mime_type = {});
+ Optional<MimeSniff::MimeType> maybe_mime_type = {}, GC::Ptr<DOM::Document> loading_container_document = {});
}
diff --git a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp
index a6d09088f2d..f9c813381a7 100644
--- a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp
@@ -28,13 +28,14 @@ static Utf16String utf16_string_from_standardized_encoding_label(StringView labe
return Utf16String::from_ascii_without_validation(label.bytes());
}
-GC::Ref<IncrementalDocumentParser> IncrementalDocumentParser::create(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response)
+GC::Ref<IncrementalDocumentParser> IncrementalDocumentParser::create(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response, GC::Ptr<DOM::Document> container_document)
{
- return GC::Heap::the().allocate<IncrementalDocumentParser>(document, response);
+ return GC::Heap::the().allocate<IncrementalDocumentParser>(document, response, container_document);
}
-IncrementalDocumentParser::IncrementalDocumentParser(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response)
+IncrementalDocumentParser::IncrementalDocumentParser(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response, GC::Ptr<DOM::Document> container_document)
: m_document(document)
+ , m_container_document(container_document)
, m_body(response.body())
, m_url(response.url().value())
, m_mime_type(Fetch::Infrastructure::extract_mime_type(response.header_list()))
@@ -46,6 +47,7 @@ void IncrementalDocumentParser::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_document);
+ visitor.visit(m_container_document);
visitor.visit(m_body);
visitor.visit(m_parser);
}
@@ -84,7 +86,7 @@ void IncrementalDocumentParser::initialize_parser(ReadonlyBytes sniff_bytes)
if (m_document->has_encoding()) {
standardized_encoding = TextCodec::get_standardized_encoding(m_document->encoding().value());
} else {
- auto [encoding, confidence] = run_encoding_sniffing_algorithm(m_document, sniff_bytes, m_mime_type);
+ auto [encoding, confidence] = run_encoding_sniffing_algorithm(m_document, sniff_bytes, m_mime_type, m_container_document);
standardized_encoding = TextCodec::get_standardized_encoding(encoding);
encoding_confidence = confidence;
}
diff --git a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h
index fe24111629c..f275a52e4f4 100644
--- a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h
+++ b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h
@@ -28,13 +28,13 @@ class WEB_API IncrementalDocumentParser final : public JS::Cell {
GC_DECLARE_ALLOCATOR(IncrementalDocumentParser);
public:
- static GC::Ref<IncrementalDocumentParser> create(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&);
+ static GC::Ref<IncrementalDocumentParser> create(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&, GC::Ptr<DOM::Document> container_document);
void start();
void set_allow_declarative_shadow_roots(HTMLParser::AllowDeclarativeShadowRoots);
private:
- IncrementalDocumentParser(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&);
+ IncrementalDocumentParser(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&, GC::Ptr<DOM::Document> container_document);
virtual void visit_edges(Cell::Visitor&) override;
@@ -60,6 +60,7 @@ private:
ReadonlyBytes undecoded_input_bytes() const;
GC::Ref<DOM::Document> m_document;
+ GC::Ptr<DOM::Document> m_container_document;
GC::Ptr<Fetch::Infrastructure::Body> m_body;
URL::URL m_url;
Optional<MimeSniff::MimeType> m_mime_type;
diff --git a/Tests/LibWeb/Assets/encoding-sniffing/no-declaration.html b/Tests/LibWeb/Assets/encoding-sniffing/no-declaration.html
new file mode 100644
index 00000000000..2a8f2eb968a
--- /dev/null
+++ b/Tests/LibWeb/Assets/encoding-sniffing/no-declaration.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<p>HTML with no encoding declaration.</p>
diff --git a/Tests/LibWeb/Assets/encoding-sniffing/plain.txt b/Tests/LibWeb/Assets/encoding-sniffing/plain.txt
new file mode 100644
index 00000000000..22fc14212c6
--- /dev/null
+++ b/Tests/LibWeb/Assets/encoding-sniffing/plain.txt
@@ -0,0 +1 @@
+Plain text with no encoding declaration.
diff --git a/Tests/LibWeb/Text/expected/HTML/encoding-sniffing-inherits-parent-encoding.txt b/Tests/LibWeb/Text/expected/HTML/encoding-sniffing-inherits-parent-encoding.txt
new file mode 100644
index 00000000000..f5ff864878b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/encoding-sniffing-inherits-parent-encoding.txt
@@ -0,0 +1,4 @@
+parent: Shift_JIS
+no-declaration.html: Shift_JIS
+plain.txt: Shift_JIS
+text/plain blob: Shift_JIS
diff --git a/Tests/LibWeb/Text/expected/wpt-import/encoding/unsupported-labels.window.txt b/Tests/LibWeb/Text/expected/wpt-import/encoding/unsupported-labels.window.txt
index c01daf9d103..673dea9f8e0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/encoding/unsupported-labels.window.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/encoding/unsupported-labels.window.txt
@@ -2,162 +2,162 @@ Harness status: OK
Found 158 tests
-158 Fail
-Fail 437 is not supported by the Encoding Standard
-Fail adobe-standard-encoding is not supported by the Encoding Standard
-Fail armscii-8 is not supported by the Encoding Standard
-Fail bocu-1 is not supported by the Encoding Standard
-Fail cesu-8 is not supported by the Encoding Standard
-Fail cp1025 is not supported by the Encoding Standard
-Fail cp437 is not supported by the Encoding Standard
-Fail cp737 is not supported by the Encoding Standard
-Fail cp851 is not supported by the Encoding Standard
-Fail cp858 is not supported by the Encoding Standard
-Fail cp862 is not supported by the Encoding Standard
-Fail cp864 is not supported by the Encoding Standard
-Fail cp869 is not supported by the Encoding Standard
-Fail cp875 is not supported by the Encoding Standard
-Fail cp950 is not supported by the Encoding Standard
-Fail csiso103t618bit is not supported by the Encoding Standard
-Fail csiso111ecmacyrillic is not supported by the Encoding Standard
-Fail cspc8codepage437 is not supported by the Encoding Standard
-Fail csviscii is not supported by the Encoding Standard
-Fail dos-720 is not supported by the Encoding Standard
-Fail dos-862 is not supported by the Encoding Standard
-Fail ecma-cyrillic is not supported by the Encoding Standard
-Fail euc-tw is not supported by the Encoding Standard
-Fail german is not supported by the Encoding Standard
-Fail geostd8 is not supported by the Encoding Standard
-Fail hp-roman8 is not supported by the Encoding Standard
-Fail ibm-thai is not supported by the Encoding Standard
-Fail ibm00858 is not supported by the Encoding Standard
-Fail ibm00924 is not supported by the Encoding Standard
-Fail ibm01047 is not supported by the Encoding Standard
-Fail ibm01140 is not supported by the Encoding Standard
-Fail ibm01141 is not supported by the Encoding Standard
-Fail ibm01142 is not supported by the Encoding Standard
-Fail ibm01143 is not supported by the Encoding Standard
-Fail ibm01144 is not supported by the Encoding Standard
-Fail ibm01145 is not supported by the Encoding Standard
-Fail ibm01146 is not supported by the Encoding Standard
-Fail ibm01147 is not supported by the Encoding Standard
-Fail ibm01148 is not supported by the Encoding Standard
-Fail ibm01149 is not supported by the Encoding Standard
-Fail ibm037 is not supported by the Encoding Standard
-Fail ibm1026 is not supported by the Encoding Standard
-Fail ibm1047 is not supported by the Encoding Standard
-Fail ibm273 is not supported by the Encoding Standard
-Fail ibm277 is not supported by the Encoding Standard
-Fail ibm278 is not supported by the Encoding Standard
-Fail ibm280 is not supported by the Encoding Standard
-Fail ibm284 is not supported by the Encoding Standard
-Fail ibm285 is not supported by the Encoding Standard
-Fail ibm290 is not supported by the Encoding Standard
-Fail ibm297 is not supported by the Encoding Standard
-Fail ibm367 is not supported by the Encoding Standard
-Fail ibm420 is not supported by the Encoding Standard
-Fail ibm423 is not supported by the Encoding Standard
-Fail ibm424 is not supported by the Encoding Standard
-Fail ibm437 is not supported by the Encoding Standard
-Fail ibm500 is not supported by the Encoding Standard
-Fail ibm737 is not supported by the Encoding Standard
-Fail ibm775 is not supported by the Encoding Standard
-Fail ibm850 is not supported by the Encoding Standard
-Fail ibm852 is not supported by the Encoding Standard
-Fail ibm855 is not supported by the Encoding Standard
-Fail ibm857 is not supported by the Encoding Standard
-Fail ibm860 is not supported by the Encoding Standard
-Fail ibm861 is not supported by the Encoding Standard
-Fail ibm862 is not supported by the Encoding Standard
-Fail ibm863 is not supported by the Encoding Standard
-Fail ibm864 is not supported by the Encoding Standard
-Fail ibm864i is not supported by the Encoding Standard
-Fail ibm865 is not supported by the Encoding Standard
-Fail ibm868 is not supported by the Encoding Standard
-Fail ibm869 is not supported by the Encoding Standard
-Fail ibm870 is not supported by the Encoding Standard
-Fail ibm871 is not supported by the Encoding Standard
-Fail ibm880 is not supported by the Encoding Standard
-Fail ibm905 is not supported by the Encoding Standard
-Fail ibm918 is not supported by the Encoding Standard
-Fail iso-2022-jp-1 is not supported by the Encoding Standard
-Fail iso-2022-jp-2 is not supported by the Encoding Standard
-Fail iso-2022-jp-3 is not supported by the Encoding Standard
-Fail iso-8859-8 visual is not supported by the Encoding Standard
-Fail jis_c6226-1978 is not supported by the Encoding Standard
-Fail jis_x0208-1983 is not supported by the Encoding Standard
-Fail jis_x0208-1990 is not supported by the Encoding Standard
-Fail jis_x0212-1990 is not supported by the Encoding Standard
-Fail johab is not supported by the Encoding Standard
-Fail latin9 is not supported by the Encoding Standard
-Fail norwegian is not supported by the Encoding Standard
-Fail sami-ws2 is not supported by the Encoding Standard
-Fail scsu is not supported by the Encoding Standard
-Fail shift_jis_x0213-2000 is not supported by the Encoding Standard
-Fail swedish is not supported by the Encoding Standard
-Fail tcvn is not supported by the Encoding Standard
-Fail tis-620-2533 is not supported by the Encoding Standard
-Fail utf-7 is not supported by the Encoding Standard
-Fail utf-32 is not supported by the Encoding Standard
-Fail viscii is not supported by the Encoding Standard
-Fail windows-936-2000 is not supported by the Encoding Standard
-Fail windows-sami-2 is not supported by the Encoding Standard
-Fail ws2 is not supported by the Encoding Standard
-Fail x-chinese-cns is not supported by the Encoding Standard
-Fail x-chinese-eten is not supported by the Encoding Standard
-Fail x-cp20001 is not supported by the Encoding Standard
-Fail x-cp20003 is not supported by the Encoding Standard
-Fail x-cp20004 is not supported by the Encoding Standard
-Fail x-cp20005 is not supported by the Encoding Standard
-Fail x-cp20261 is not supported by the Encoding Standard
-Fail x-cp20269 is not supported by the Encoding Standard
-Fail x-cp20936 is not supported by the Encoding Standard
-Fail x-cp20949 is not supported by the Encoding Standard
-Fail x-cp21027 is not supported by the Encoding Standard
-Fail x-cp50227 is not supported by the Encoding Standard
-Fail x-cp50229 is not supported by the Encoding Standard
-Fail x-ebcdic-koreanextended is not supported by the Encoding Standard
-Fail x-europa is not supported by the Encoding Standard
-Fail x-ia5 is not supported by the Encoding Standard
-Fail x-ia5-german is not supported by the Encoding Standard
-Fail x-ia5-norwegian is not supported by the Encoding Standard
-Fail x-ia5-swedish is not supported by the Encoding Standard
-Fail x-iscii-as is not supported by the Encoding Standard
-Fail x-iscii-be is not supported by the Encoding Standard
-Fail x-iscii-de is not supported by the Encoding Standard
-Fail x-iscii-gu is not supported by the Encoding Standard
-Fail x-iscii-ka is not supported by the Encoding Standard
-Fail x-iscii-ma is not supported by the Encoding Standard
-Fail x-iscii-or is not supported by the Encoding Standard
-Fail x-iscii-pa is not supported by the Encoding Standard
-Fail x-iscii-t is not supported by the Encoding Standard
-Fail x-iscii-ta is not supported by the Encoding Standard
-Fail x-iscii-te is not supported by the Encoding Standard
-Fail x-mac-arabic is not supported by the Encoding Standard
-Fail x-mac-ce is not supported by the Encoding Standard
-Fail x-mac-centraleurroman is not supported by the Encoding Standard
-Fail x-mac-chinesesimp is not supported by the Encoding Standard
-Fail x-mac-chinesetrad is not supported by the Encoding Standard
-Fail x-mac-croatian is not supported by the Encoding Standard
-Fail x-mac-devanagari is not supported by the Encoding Standard
-Fail x-mac-dingbats is not supported by the Encoding Standard
-Fail x-mac-farsi is not supported by the Encoding Standard
-Fail x-mac-greek is not supported by the Encoding Standard
-Fail x-mac-gujarati is not supported by the Encoding Standard
-Fail x-mac-gurmukhi is not supported by the Encoding Standard
-Fail x-mac-hebrew is not supported by the Encoding Standard
-Fail x-mac-icelandic is not supported by the Encoding Standard
-Fail x-mac-japanese is not supported by the Encoding Standard
-Fail x-mac-korean is not supported by the Encoding Standard
-Fail x-mac-roman-latin1 is not supported by the Encoding Standard
-Fail x-mac-romanian is not supported by the Encoding Standard
-Fail x-mac-symbol is not supported by the Encoding Standard
-Fail x-mac-thai is not supported by the Encoding Standard
-Fail x-mac-tibetan is not supported by the Encoding Standard
-Fail x-mac-turkish is not supported by the Encoding Standard
-Fail x-mac-vt100 is not supported by the Encoding Standard
-Fail x-nextstep is not supported by the Encoding Standard
-Fail x-vps is not supported by the Encoding Standard
-Fail _autodetect is not supported by the Encoding Standard
-Fail _autodetect_all is not supported by the Encoding Standard
-Fail _autodetect_kr is not supported by the Encoding Standard
\ No newline at end of file
+158 Pass
+Pass 437 is not supported by the Encoding Standard
+Pass adobe-standard-encoding is not supported by the Encoding Standard
+Pass armscii-8 is not supported by the Encoding Standard
+Pass bocu-1 is not supported by the Encoding Standard
+Pass cesu-8 is not supported by the Encoding Standard
+Pass cp1025 is not supported by the Encoding Standard
+Pass cp437 is not supported by the Encoding Standard
+Pass cp737 is not supported by the Encoding Standard
+Pass cp851 is not supported by the Encoding Standard
+Pass cp858 is not supported by the Encoding Standard
+Pass cp862 is not supported by the Encoding Standard
+Pass cp864 is not supported by the Encoding Standard
+Pass cp869 is not supported by the Encoding Standard
+Pass cp875 is not supported by the Encoding Standard
+Pass cp950 is not supported by the Encoding Standard
+Pass csiso103t618bit is not supported by the Encoding Standard
+Pass csiso111ecmacyrillic is not supported by the Encoding Standard
+Pass cspc8codepage437 is not supported by the Encoding Standard
+Pass csviscii is not supported by the Encoding Standard
+Pass dos-720 is not supported by the Encoding Standard
+Pass dos-862 is not supported by the Encoding Standard
+Pass ecma-cyrillic is not supported by the Encoding Standard
+Pass euc-tw is not supported by the Encoding Standard
+Pass german is not supported by the Encoding Standard
+Pass geostd8 is not supported by the Encoding Standard
+Pass hp-roman8 is not supported by the Encoding Standard
+Pass ibm-thai is not supported by the Encoding Standard
+Pass ibm00858 is not supported by the Encoding Standard
+Pass ibm00924 is not supported by the Encoding Standard
+Pass ibm01047 is not supported by the Encoding Standard
+Pass ibm01140 is not supported by the Encoding Standard
+Pass ibm01141 is not supported by the Encoding Standard
+Pass ibm01142 is not supported by the Encoding Standard
+Pass ibm01143 is not supported by the Encoding Standard
+Pass ibm01144 is not supported by the Encoding Standard
+Pass ibm01145 is not supported by the Encoding Standard
+Pass ibm01146 is not supported by the Encoding Standard
+Pass ibm01147 is not supported by the Encoding Standard
+Pass ibm01148 is not supported by the Encoding Standard
+Pass ibm01149 is not supported by the Encoding Standard
+Pass ibm037 is not supported by the Encoding Standard
+Pass ibm1026 is not supported by the Encoding Standard
+Pass ibm1047 is not supported by the Encoding Standard
+Pass ibm273 is not supported by the Encoding Standard
+Pass ibm277 is not supported by the Encoding Standard
+Pass ibm278 is not supported by the Encoding Standard
+Pass ibm280 is not supported by the Encoding Standard
+Pass ibm284 is not supported by the Encoding Standard
+Pass ibm285 is not supported by the Encoding Standard
+Pass ibm290 is not supported by the Encoding Standard
+Pass ibm297 is not supported by the Encoding Standard
+Pass ibm367 is not supported by the Encoding Standard
+Pass ibm420 is not supported by the Encoding Standard
+Pass ibm423 is not supported by the Encoding Standard
+Pass ibm424 is not supported by the Encoding Standard
+Pass ibm437 is not supported by the Encoding Standard
+Pass ibm500 is not supported by the Encoding Standard
+Pass ibm737 is not supported by the Encoding Standard
+Pass ibm775 is not supported by the Encoding Standard
+Pass ibm850 is not supported by the Encoding Standard
+Pass ibm852 is not supported by the Encoding Standard
+Pass ibm855 is not supported by the Encoding Standard
+Pass ibm857 is not supported by the Encoding Standard
+Pass ibm860 is not supported by the Encoding Standard
+Pass ibm861 is not supported by the Encoding Standard
+Pass ibm862 is not supported by the Encoding Standard
+Pass ibm863 is not supported by the Encoding Standard
+Pass ibm864 is not supported by the Encoding Standard
+Pass ibm864i is not supported by the Encoding Standard
+Pass ibm865 is not supported by the Encoding Standard
+Pass ibm868 is not supported by the Encoding Standard
+Pass ibm869 is not supported by the Encoding Standard
+Pass ibm870 is not supported by the Encoding Standard
+Pass ibm871 is not supported by the Encoding Standard
+Pass ibm880 is not supported by the Encoding Standard
+Pass ibm905 is not supported by the Encoding Standard
+Pass ibm918 is not supported by the Encoding Standard
+Pass iso-2022-jp-1 is not supported by the Encoding Standard
+Pass iso-2022-jp-2 is not supported by the Encoding Standard
+Pass iso-2022-jp-3 is not supported by the Encoding Standard
+Pass iso-8859-8 visual is not supported by the Encoding Standard
+Pass jis_c6226-1978 is not supported by the Encoding Standard
+Pass jis_x0208-1983 is not supported by the Encoding Standard
+Pass jis_x0208-1990 is not supported by the Encoding Standard
+Pass jis_x0212-1990 is not supported by the Encoding Standard
+Pass johab is not supported by the Encoding Standard
+Pass latin9 is not supported by the Encoding Standard
+Pass norwegian is not supported by the Encoding Standard
+Pass sami-ws2 is not supported by the Encoding Standard
+Pass scsu is not supported by the Encoding Standard
+Pass shift_jis_x0213-2000 is not supported by the Encoding Standard
+Pass swedish is not supported by the Encoding Standard
+Pass tcvn is not supported by the Encoding Standard
+Pass tis-620-2533 is not supported by the Encoding Standard
+Pass utf-7 is not supported by the Encoding Standard
+Pass utf-32 is not supported by the Encoding Standard
+Pass viscii is not supported by the Encoding Standard
+Pass windows-936-2000 is not supported by the Encoding Standard
+Pass windows-sami-2 is not supported by the Encoding Standard
+Pass ws2 is not supported by the Encoding Standard
+Pass x-chinese-cns is not supported by the Encoding Standard
+Pass x-chinese-eten is not supported by the Encoding Standard
+Pass x-cp20001 is not supported by the Encoding Standard
+Pass x-cp20003 is not supported by the Encoding Standard
+Pass x-cp20004 is not supported by the Encoding Standard
+Pass x-cp20005 is not supported by the Encoding Standard
+Pass x-cp20261 is not supported by the Encoding Standard
+Pass x-cp20269 is not supported by the Encoding Standard
+Pass x-cp20936 is not supported by the Encoding Standard
+Pass x-cp20949 is not supported by the Encoding Standard
+Pass x-cp21027 is not supported by the Encoding Standard
+Pass x-cp50227 is not supported by the Encoding Standard
+Pass x-cp50229 is not supported by the Encoding Standard
+Pass x-ebcdic-koreanextended is not supported by the Encoding Standard
+Pass x-europa is not supported by the Encoding Standard
+Pass x-ia5 is not supported by the Encoding Standard
+Pass x-ia5-german is not supported by the Encoding Standard
+Pass x-ia5-norwegian is not supported by the Encoding Standard
+Pass x-ia5-swedish is not supported by the Encoding Standard
+Pass x-iscii-as is not supported by the Encoding Standard
+Pass x-iscii-be is not supported by the Encoding Standard
+Pass x-iscii-de is not supported by the Encoding Standard
+Pass x-iscii-gu is not supported by the Encoding Standard
+Pass x-iscii-ka is not supported by the Encoding Standard
+Pass x-iscii-ma is not supported by the Encoding Standard
+Pass x-iscii-or is not supported by the Encoding Standard
+Pass x-iscii-pa is not supported by the Encoding Standard
+Pass x-iscii-t is not supported by the Encoding Standard
+Pass x-iscii-ta is not supported by the Encoding Standard
+Pass x-iscii-te is not supported by the Encoding Standard
+Pass x-mac-arabic is not supported by the Encoding Standard
+Pass x-mac-ce is not supported by the Encoding Standard
+Pass x-mac-centraleurroman is not supported by the Encoding Standard
+Pass x-mac-chinesesimp is not supported by the Encoding Standard
+Pass x-mac-chinesetrad is not supported by the Encoding Standard
+Pass x-mac-croatian is not supported by the Encoding Standard
+Pass x-mac-devanagari is not supported by the Encoding Standard
+Pass x-mac-dingbats is not supported by the Encoding Standard
+Pass x-mac-farsi is not supported by the Encoding Standard
+Pass x-mac-greek is not supported by the Encoding Standard
+Pass x-mac-gujarati is not supported by the Encoding Standard
+Pass x-mac-gurmukhi is not supported by the Encoding Standard
+Pass x-mac-hebrew is not supported by the Encoding Standard
+Pass x-mac-icelandic is not supported by the Encoding Standard
+Pass x-mac-japanese is not supported by the Encoding Standard
+Pass x-mac-korean is not supported by the Encoding Standard
+Pass x-mac-roman-latin1 is not supported by the Encoding Standard
+Pass x-mac-romanian is not supported by the Encoding Standard
+Pass x-mac-symbol is not supported by the Encoding Standard
+Pass x-mac-thai is not supported by the Encoding Standard
+Pass x-mac-tibetan is not supported by the Encoding Standard
+Pass x-mac-turkish is not supported by the Encoding Standard
+Pass x-mac-vt100 is not supported by the Encoding Standard
+Pass x-nextstep is not supported by the Encoding Standard
+Pass x-vps is not supported by the Encoding Standard
+Pass _autodetect is not supported by the Encoding Standard
+Pass _autodetect_all is not supported by the Encoding Standard
+Pass _autodetect_kr is not supported by the Encoding Standard
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/syntax/xmldecl/xmldecl-2.txt b/Tests/LibWeb/Text/expected/wpt-import/html/syntax/xmldecl/xmldecl-2.txt
index 36f57b8cb15..e38e70420db 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/syntax/xmldecl/xmldecl-2.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/syntax/xmldecl/xmldecl-2.txt
@@ -2,36 +2,35 @@ Harness status: OK
Found 47 tests
-23 Pass
-24 Fail
+47 Pass
Pass Check encoding windows-1251, kilobyte-plus-one-after.htm
Pass Check encoding windows-1251, kilobyte-plus-one-before.htm
Pass Check encoding windows-1251, kilobyte-plus-one-after-trail.htm
Pass Check encoding windows-1251, kilobyte-plus-one-before-trail.htm
-Fail Check encoding windows-1252, encodingencoding.htm
-Fail Check encoding windows-1252, encoding-equals-encoding.htm
-Fail Check encoding windows-1252, ENCODING.htm
-Fail Check encoding windows-1252, gt-between-xml-and-encoding.htm
-Fail Check encoding windows-1252, no-quotes.htm
-Fail Check encoding windows-1252, no-quotes-space.htm
-Fail Check encoding windows-1252, one-around-label.htm
-Fail Check encoding windows-1252, space-around-label.htm
-Fail Check encoding windows-1252, space-before.htm
-Fail Check encoding windows-1252, unmatched-quotes.htm
-Fail Check encoding windows-1252, XML.htm
-Fail Check encoding windows-1252, zero-around-label.htm
-Fail Check encoding windows-1252, encodingencoding-trail.htm
-Fail Check encoding windows-1252, encoding-equals-encoding-trail.htm
-Fail Check encoding windows-1252, ENCODING-trail.htm
-Fail Check encoding windows-1252, gt-between-xml-and-encoding-trail.htm
-Fail Check encoding windows-1252, no-quotes-trail.htm
-Fail Check encoding windows-1252, no-quotes-space-trail.htm
-Fail Check encoding windows-1252, one-around-label-trail.htm
-Fail Check encoding windows-1252, space-around-label-trail.htm
-Fail Check encoding windows-1252, space-before-trail.htm
-Fail Check encoding windows-1252, unmatched-quotes-trail.htm
-Fail Check encoding windows-1252, XML-trail.htm
-Fail Check encoding windows-1252, zero-around-label-trail.htm
+Pass Check encoding windows-1252, encodingencoding.htm
+Pass Check encoding windows-1252, encoding-equals-encoding.htm
+Pass Check encoding windows-1252, ENCODING.htm
+Pass Check encoding windows-1252, gt-between-xml-and-encoding.htm
+Pass Check encoding windows-1252, no-quotes.htm
+Pass Check encoding windows-1252, no-quotes-space.htm
+Pass Check encoding windows-1252, one-around-label.htm
+Pass Check encoding windows-1252, space-around-label.htm
+Pass Check encoding windows-1252, space-before.htm
+Pass Check encoding windows-1252, unmatched-quotes.htm
+Pass Check encoding windows-1252, XML.htm
+Pass Check encoding windows-1252, zero-around-label.htm
+Pass Check encoding windows-1252, encodingencoding-trail.htm
+Pass Check encoding windows-1252, encoding-equals-encoding-trail.htm
+Pass Check encoding windows-1252, ENCODING-trail.htm
+Pass Check encoding windows-1252, gt-between-xml-and-encoding-trail.htm
+Pass Check encoding windows-1252, no-quotes-trail.htm
+Pass Check encoding windows-1252, no-quotes-space-trail.htm
+Pass Check encoding windows-1252, one-around-label-trail.htm
+Pass Check encoding windows-1252, space-around-label-trail.htm
+Pass Check encoding windows-1252, space-before-trail.htm
+Pass Check encoding windows-1252, unmatched-quotes-trail.htm
+Pass Check encoding windows-1252, XML-trail.htm
+Pass Check encoding windows-1252, zero-around-label-trail.htm
Pass Check encoding windows-1253, xml-and-meta.htm
Pass Check encoding windows-1253, incomplete-utf-16le-and-meta.htm
Pass Check encoding windows-1253, incomplete-utf-16be-and-meta.htm
diff --git a/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html b/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html
new file mode 100644
index 00000000000..bf097470a35
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<meta charset="shift_jis">
+<script src="../include.js"></script>
+<script>
+ async function loadFrame(src) {
+ const iframe = document.createElement("iframe");
+ iframe.src = src;
+ document.body.append(iframe);
+ await new Promise(resolve => (iframe.onload = resolve));
+ return iframe.contentDocument.characterSet;
+ }
+
+ asyncTest(async done => {
+ println(`parent: ${document.characterSet}`);
+ for (const name of ["no-declaration.html", "plain.txt"])
+ println(`${name}: ${await loadFrame(`../../../Assets/encoding-sniffing/${name}`)}`);
+ const blob = new Blob(["Plain text with no encoding declaration.\n"], { type: "text/plain" });
+ println(`text/plain blob: ${await loadFrame(URL.createObjectURL(blob))}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html.headers b/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html.headers
new file mode 100644
index 00000000000..156209f9c81
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/encoding-sniffing-inherits-parent-encoding.html.headers
@@ -0,0 +1 @@
+Content-Type: text/html