Skip to content

Commit

Permalink
Revert "LibWeb: Set doctype node immediately while parsing XML document"
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 committed Nov 20, 2024
1 parent 63a5717 commit 0c5a672
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 66 deletions.
6 changes: 3 additions & 3 deletions Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void XMLDocumentBuilder::set_source(ByteString source)
m_document->set_source(MUST(String::from_byte_string(source)));
}

void XMLDocumentBuilder::doctype(XML::Doctype const& doctype)
void XMLDocumentBuilder::set_doctype(XML::Doctype doctype)
{
if (m_document->doctype()) {
return;
Expand All @@ -73,13 +73,13 @@ void XMLDocumentBuilder::doctype(XML::Doctype const& doctype)
document_type->set_name(name);

if (doctype.external_id.has_value()) {
auto const& external_id = *doctype.external_id;
auto external_id = doctype.external_id.release_value();

auto system_id = MUST(AK::String::from_byte_string(external_id.system_id.system_literal));
document_type->set_system_id(system_id);

if (external_id.public_id.has_value()) {
auto public_id = MUST(AK::String::from_byte_string(external_id.public_id->public_literal));
auto public_id = MUST(AK::String::from_byte_string(external_id.public_id.release_value().public_literal));
document_type->set_public_id(public_id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/XML/XMLDocumentBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class XMLDocumentBuilder final : public XML::Listener {

private:
virtual void set_source(ByteString) override;
virtual void doctype(XML::Doctype const&) override;
virtual void set_doctype(XML::Doctype) override;
virtual void element_start(XML::Name const& name, HashMap<XML::Name, ByteString> const& attributes) override;
virtual void element_end(XML::Name const& name) override;
virtual void text(StringView data) override;
Expand Down
6 changes: 4 additions & 2 deletions Libraries/LibXML/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ ErrorOr<void, ParseError> Parser::parse_with_listener(Listener& listener)
if (result.is_error())
m_listener->error(result.error());
m_listener->document_end();
if (m_doctype.has_value()) {
m_listener->set_doctype(m_doctype.release_value());
}
m_root_node.clear();
return result;
}
Expand Down Expand Up @@ -618,8 +621,7 @@ ErrorOr<void, ParseError> Parser::parse_doctype_decl()
TRY(expect(">"sv));

rollback.disarm();
if (m_listener)
m_listener->doctype(doctype);
m_doctype = move(doctype);
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibXML/Parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ struct Listener {
virtual ~Listener() { }

virtual void set_source(ByteString) { }
virtual void set_doctype(XML::Doctype) { }
virtual void document_start() { }
virtual void document_end() { }
virtual void doctype(Doctype const&) { }
virtual void element_start(Name const&, HashMap<Name, ByteString> const&) { }
virtual void element_end(Name const&) { }
virtual void text(StringView) { }
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 0c5a672

Please sign in to comment.