1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

html: Move DTD creation to endDocument SAX callback

This commit is contained in:
Nick Wellnhofer
2025-05-09 15:26:15 +02:00
parent 46f05ea4d5
commit c7c4964342
2 changed files with 16 additions and 28 deletions

View File

@@ -4331,8 +4331,6 @@ htmlCtxtParseContentInternal(htmlParserCtxtPtr ctxt, xmlParserInputPtr input) {
*/
int
htmlParseDocument(htmlParserCtxtPtr ctxt) {
xmlDtdPtr dtd;
if ((ctxt == NULL) || (ctxt->input == NULL))
return(-1);
@@ -4429,17 +4427,6 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
ctxt->sax->endDocument(ctxt->userData);
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) && (ctxt->myDoc != NULL)) {
dtd = xmlGetIntSubset(ctxt->myDoc);
if (dtd == NULL) {
ctxt->myDoc->intSubset =
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
if (ctxt->myDoc->intSubset == NULL)
htmlErrMemory(ctxt);
}
}
if (! ctxt->wellFormed) return(-1);
return(0);
}
@@ -5158,20 +5145,6 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
ctxt->sax->endDocument(ctxt->userData);
if ((!(ctxt->options & HTML_PARSE_NODEFDTD)) &&
(ctxt->myDoc != NULL)) {
xmlDtdPtr dtd;
dtd = xmlGetIntSubset(ctxt->myDoc);
if (dtd == NULL) {
ctxt->myDoc->intSubset =
xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
if (ctxt->myDoc->intSubset == NULL)
htmlErrMemory(ctxt);
}
}
ctxt->instate = XML_PARSER_EOF;
}

17
SAX2.c
View File

@@ -837,7 +837,10 @@ xmlSAX2EndDocument(void *ctx)
#endif /* LIBXML_VALID_ENABLED */
doc = ctxt->myDoc;
if ((doc != NULL) && (doc->encoding == NULL)) {
if (doc == NULL)
return;
if (doc->encoding == NULL) {
const xmlChar *encoding = xmlGetActualEncoding(ctxt);
if (encoding != NULL) {
@@ -846,6 +849,18 @@ xmlSAX2EndDocument(void *ctx)
xmlSAX2ErrMemory(ctxt);
}
}
#ifdef LIBXML_HTML_ENABLED
if ((ctxt->html) &&
((ctxt->options & HTML_PARSE_NODEFDTD) == 0) &&
(doc->intSubset == NULL)) {
doc->intSubset = xmlCreateIntSubset(doc, BAD_CAST "html",
BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
if (doc->intSubset == NULL)
xmlSAX2ErrMemory(ctxt);
}
#endif /* LIBXML_HTML_ENABLED */
}
static void