LibWeb: Use fatal decoding when loading XML documents
Decode XML document bytes with TextCodec::ErrorMode::Fatal and treat decode failure as an XML loading error. This removes the separate decoder validation pass and lets the decode operation itself enforce XML's requirement that documents contain only properly encoded characters.
This commit is contained in:
parent
ef6753a9f9
commit
b9da74d16e
1 changed files with 3 additions and 8 deletions
|
|
@ -73,11 +73,12 @@ bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optiona
|
|||
}
|
||||
VERIFY(decoder.has_value());
|
||||
// Well-formed XML documents contain only properly encoded characters
|
||||
if (!decoder->validate(data)) {
|
||||
auto source_or_error = decoder->to_utf8(data, TextCodec::IgnoreBOM::No, TextCodec::ErrorMode::Fatal);
|
||||
if (source_or_error.is_error()) {
|
||||
convert_to_xml_error_document(document, "XML Document contains improperly-encoded characters"_utf16);
|
||||
return false;
|
||||
}
|
||||
auto source = decoder->to_utf8(data, TextCodec::IgnoreBOM::No, TextCodec::ErrorMode::Fatal).release_value_but_fixme_should_propagate_errors();
|
||||
auto source = source_or_error.release_value();
|
||||
XML::Parser parser(source, { .resolve_named_html_entity = resolve_named_html_entity });
|
||||
XMLDocumentBuilder builder { document };
|
||||
auto result = parser.parse_with_listener(builder);
|
||||
|
|
@ -198,12 +199,6 @@ static WebIDL::ExceptionOr<GC::Ref<DOM::Document>> load_xml_document(HTML::Navig
|
|||
}
|
||||
VERIFY(decoder.has_value());
|
||||
// Well-formed XML documents contain only properly encoded characters
|
||||
if (!decoder->validate(data)) {
|
||||
// FIXME: Insert error message into the document.
|
||||
dbgln("XML Document contains improperly-encoded characters");
|
||||
convert_to_xml_error_document(document, "XML Document contains improperly-encoded characters"_utf16);
|
||||
return;
|
||||
}
|
||||
auto source = decoder->to_utf8(data, TextCodec::IgnoreBOM::No, TextCodec::ErrorMode::Fatal);
|
||||
if (source.is_error()) {
|
||||
// FIXME: Insert error message into the document.
|
||||
|
|
|
|||
Loading…
Reference in a new issue