1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

541335 HTML avoid creating 2 head or 2 body element

* HTMLparser.c: check when we see an head or a body tag and avoid
  autogenerating them
* include/libxml/parser.h: the values for ctxt->html change depending
  on the head or body tags being seen
This commit is contained in:
Daniel Veillard
2009-08-24 12:50:23 +02:00
parent 6339c1a886
commit 029a04d265
2 changed files with 23 additions and 8 deletions

View File

@ -163,6 +163,10 @@ htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
static int static int
htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value) htmlnamePush(htmlParserCtxtPtr ctxt, const xmlChar * value)
{ {
if ((ctxt->html < 3) && (xmlStrEqual(value, BAD_CAST "head")))
ctxt->html = 3;
if ((ctxt->html < 10) && (xmlStrEqual(value, BAD_CAST "body")))
ctxt->html = 10;
if (ctxt->nameNr >= ctxt->nameMax) { if (ctxt->nameNr >= ctxt->nameMax) {
ctxt->nameMax *= 2; ctxt->nameMax *= 2;
ctxt->nameTab = (const xmlChar * *) ctxt->nameTab = (const xmlChar * *)
@ -1393,6 +1397,10 @@ htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
(xmlStrEqual(newtag, BAD_CAST"link")) || (xmlStrEqual(newtag, BAD_CAST"link")) ||
(xmlStrEqual(newtag, BAD_CAST"title")) || (xmlStrEqual(newtag, BAD_CAST"title")) ||
(xmlStrEqual(newtag, BAD_CAST"base")))) { (xmlStrEqual(newtag, BAD_CAST"base")))) {
if (ctxt->html >= 3) {
/* we already saw or generated an <head> before */
return;
}
/* /*
* dropped OBJECT ... i you put it first BODY will be * dropped OBJECT ... i you put it first BODY will be
* assumed ! * assumed !
@ -1403,6 +1411,10 @@ htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
} else if ((!xmlStrEqual(newtag, BAD_CAST"noframes")) && } else if ((!xmlStrEqual(newtag, BAD_CAST"noframes")) &&
(!xmlStrEqual(newtag, BAD_CAST"frame")) && (!xmlStrEqual(newtag, BAD_CAST"frame")) &&
(!xmlStrEqual(newtag, BAD_CAST"frameset"))) { (!xmlStrEqual(newtag, BAD_CAST"frameset"))) {
if (ctxt->html >= 10) {
/* we already saw or generated a <body> before */
return;
}
int i; int i;
for (i = 0;i < ctxt->nameNr;i++) { for (i = 0;i < ctxt->nameNr;i++) {
if (xmlStrEqual(ctxt->nameTab[i], BAD_CAST"body")) { if (xmlStrEqual(ctxt->nameTab[i], BAD_CAST"body")) {

View File

@ -190,7 +190,10 @@ struct _xmlParserCtxt {
const xmlChar *version; /* the XML version string */ const xmlChar *version; /* the XML version string */
const xmlChar *encoding; /* the declared encoding, if any */ const xmlChar *encoding; /* the declared encoding, if any */
int standalone; /* standalone document */ int standalone; /* standalone document */
int html; /* an HTML(1)/Docbook(2) document */ int html; /* an HTML(1)/Docbook(2) document
* 3 is HTML after <head>
* 10 is HTML after <body>
*/
/* Input stream stack */ /* Input stream stack */
xmlParserInputPtr input; /* Current input stream */ xmlParserInputPtr input; /* Current input stream */