summaryrefslogtreecommitdiff
path: root/HTMLparser.c
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2009-09-10 22:10:39 +0200
committerMike Hommey <glandium@debian.org>2009-09-10 22:10:39 +0200
commitc3e4f3c26035bc93a69e5aa2ad435809e8be8a4e (patch)
treee65557c2e042fe8a77635b0548db10ad97bc1bfe /HTMLparser.c
parente248b20a3b7df364cc9617b8685b4c190338bcd2 (diff)
downloadlibxml2-c3e4f3c26035bc93a69e5aa2ad435809e8be8a4e.tar.gz
Import upstream version 2.7.4upstream/2.7.4.dfsg
Diffstat (limited to 'HTMLparser.c')
-rw-r--r--HTMLparser.c647
1 files changed, 434 insertions, 213 deletions
diff --git a/HTMLparser.c b/HTMLparser.c
index 24b0fc0..f638511 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -59,7 +59,7 @@ static void htmlParseComment(htmlParserCtxtPtr ctxt);
/************************************************************************
* *
- * Some factorized error routines *
+ * Some factorized error routines *
* *
************************************************************************/
@@ -147,7 +147,7 @@ htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
/************************************************************************
* *
- * Parser stacks related functions and macros *
+ * Parser stacks related functions and macros *
* *
************************************************************************/
@@ -163,6 +163,10 @@ htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
static int
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) {
ctxt->nameMax *= 2;
ctxt->nameTab = (const xmlChar * *)
@@ -273,7 +277,7 @@ htmlnamePop(htmlParserCtxtPtr ctxt)
} else ctxt->input->col++; \
ctxt->token = 0; ctxt->input->cur += l; ctxt->nbChars++; \
} while (0)
-
+
/************
\
if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
@@ -288,6 +292,58 @@ htmlnamePop(htmlParserCtxtPtr ctxt)
else i += xmlCopyChar(l,&b[i],v)
/**
+ * htmlFindEncoding:
+ * @the HTML parser context
+ *
+ * Ty to find and encoding in the current data available in the input
+ * buffer this is needed to try to switch to the proper encoding when
+ * one face a character error.
+ * That's an heuristic, since it's operating outside of parsing it could
+ * try to use a meta which had been commented out, that's the reason it
+ * should only be used in case of error, not as a default.
+ *
+ * Returns an encoding string or NULL if not found, the string need to
+ * be freed
+ */
+static xmlChar *
+htmlFindEncoding(xmlParserCtxtPtr ctxt) {
+ const xmlChar *start, *cur, *end;
+
+ if ((ctxt == NULL) || (ctxt->input == NULL) ||
+ (ctxt->input->encoding != NULL) || (ctxt->input->buf == NULL) ||
+ (ctxt->input->buf->encoder != NULL))
+ return(NULL);
+ if ((ctxt->input->cur == NULL) || (ctxt->input->end == NULL))
+ return(NULL);
+
+ start = ctxt->input->cur;
+ end = ctxt->input->end;
+ /* we also expect the input buffer to be zero terminated */
+ if (*end != 0)
+ return(NULL);
+
+ cur = xmlStrcasestr(start, BAD_CAST "HTTP-EQUIV");
+ if (cur == NULL)
+ return(NULL);
+ cur = xmlStrcasestr(cur, BAD_CAST "CONTENT");
+ if (cur == NULL)
+ return(NULL);
+ cur = xmlStrcasestr(cur, BAD_CAST "CHARSET=");
+ if (cur == NULL)
+ return(NULL);
+ cur += 8;
+ start = cur;
+ while (((*cur >= 'A') && (*cur <= 'Z')) ||
+ ((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= '0') && (*cur <= '9')) ||
+ (*cur == '-') || (*cur == '_') || (*cur == ':') || (*cur == '/'))
+ cur++;
+ if (cur == start)
+ return(NULL);
+ return(xmlStrndup(start, cur - start));
+}
+
+/**
* htmlCurrentChar:
* @ctxt: the HTML parser context
* @len: pointer to the length of the char read
@@ -309,7 +365,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
if (ctxt->token != 0) {
*len = 0;
return(ctxt->token);
- }
+ }
if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
/*
* We are supposed to handle UTF8, check it's valid
@@ -318,7 +374,7 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
* UCS-4 range (hex.) UTF-8 octet sequence (binary)
* 0000 0000-0000 007F 0xxxxxxx
* 0000 0080-0000 07FF 110xxxxx 10xxxxxx
- * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
+ * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
*
* Check for the 0x110000 limit too
*/
@@ -328,19 +384,25 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
c = *cur;
if (c & 0x80) {
- if (cur[1] == 0)
+ if (cur[1] == 0) {
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ cur = ctxt->input->cur;
+ }
if ((cur[1] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xe0) == 0xe0) {
- if (cur[2] == 0)
+ if (cur[2] == 0) {
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ cur = ctxt->input->cur;
+ }
if ((cur[2] & 0xc0) != 0x80)
goto encoding_error;
if ((c & 0xf0) == 0xf0) {
- if (cur[3] == 0)
+ if (cur[3] == 0) {
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+ cur = ctxt->input->cur;
+ }
if (((c & 0xf8) != 0xf0) ||
((cur[3] & 0xc0) != 0x80))
goto encoding_error;
@@ -366,9 +428,16 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
if (!IS_CHAR(val)) {
htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR,
"Char 0x%X out of allowed range\n", val);
- }
+ }
return(val);
} else {
+ if ((*ctxt->input->cur == 0) &&
+ (ctxt->input->cur < ctxt->input->end)) {
+ htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR,
+ "Char 0x%X out of allowed range\n", 0);
+ *len = 1;
+ return(' ');
+ }
/* 1-byte code */
*len = 1;
return((int) *ctxt->input->cur);
@@ -386,8 +455,28 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
/*
* Humm this is bad, do an automatic flow conversion
*/
- xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1);
- ctxt->charset = XML_CHAR_ENCODING_UTF8;
+ {
+ xmlChar * guess;
+ xmlCharEncodingHandlerPtr handler;
+
+ guess = htmlFindEncoding(ctxt);
+ if (guess == NULL) {
+ xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1);
+ } else {
+ if (ctxt->input->encoding != NULL)
+ xmlFree((xmlChar *) ctxt->input->encoding);
+ ctxt->input->encoding = guess;
+ handler = xmlFindCharEncodingHandler((const char *) guess);
+ if (handler != NULL) {
+ xmlSwitchToEncoding(ctxt, handler);
+ } else {
+ htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
+ "Unsupported encoding %s", guess, NULL);
+ }
+ }
+ ctxt->charset = XML_CHAR_ENCODING_UTF8;
+ }
+
return(xmlCurrentChar(ctxt, len));
encoding_error:
@@ -413,7 +502,7 @@ encoding_error:
BAD_CAST buffer, NULL);
}
- ctxt->charset = XML_CHAR_ENCODING_8859_1;
+ ctxt->charset = XML_CHAR_ENCODING_8859_1;
*len = 1;
return((int) *ctxt->input->cur);
}
@@ -453,7 +542,7 @@ htmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
/************************************************************************
* *
- * The list of HTML elements and their properties *
+ * The list of HTML elements and their properties *
* *
************************************************************************/
@@ -606,7 +695,7 @@ static const char* const language_attr[] = { "language", NULL } ;
static const char* const select_content[] = { "optgroup", "option", NULL } ;
static const char* const select_attrs[] = { ATTRS, "name", "size", "multiple", "disabled", "tabindex", "onfocus", "onblur", "onchange", NULL } ;
static const char* const style_attrs[] = { I18N, "media", "title", NULL } ;
-static const char* const table_attrs[] = { ATTRS "summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding", "datapagesize", NULL } ;
+static const char* const table_attrs[] = { ATTRS, "summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding", "datapagesize", NULL } ;
static const char* const table_depr[] = { "align", "bgcolor", NULL } ;
static const char* const table_contents[] = { "caption", "col", "colgroup", "thead", "tfoot", "tbody", "tr", NULL} ;
static const char* const tr_elt[] = { "tr", NULL } ;
@@ -938,7 +1027,7 @@ static const char * const htmlStartClose[] = {
"listing", "xmp", NULL,
"ol", "p", "head", "ul", NULL,
"menu", "p", "head", "ul", NULL,
-"p", "p", "head", "h1", "h2", "h3", "h4", "h5", "h6", NULL,
+"p", "p", "head", "h1", "h2", "h3", "h4", "h5", "h6", FONTSTYLE, NULL,
"div", "p", "head", NULL,
"noscript", "p", "head", NULL,
"center", "font", "b", "i", "p", "head", NULL,
@@ -949,7 +1038,7 @@ static const char * const htmlStartClose[] = {
"table", "p", "head", "h1", "h2", "h3", "h4", "h5", "h6", "pre",
"listing", "xmp", "a", NULL,
"th", "th", "td", "p", "span", "font", "a", "b", "i", "u", NULL,
-"td", "th", "td", "p", "span", "font", "a", "b", "i", "u", NULL,
+"td", "th", "td", "p", "span", "font", "a", "b", "i", "u", NULL,
"tr", "th", "td", "tr", "caption", "col", "colgroup", "p", NULL,
"thead", "caption", "col", "colgroup", NULL,
"tfoot", "th", "td", "tr", "caption", "col", "colgroup", "thead",
@@ -1008,7 +1097,7 @@ static const char *const htmlScriptAttributes[] = {
* elements the parser can decide how to handle extra endtags.
* Endtags are only allowed to close elements with lower or equal
* priority.
- */
+ */
typedef struct {
const char *name;
@@ -1035,7 +1124,7 @@ static int htmlStartCloseIndexinitialized = 0;
/************************************************************************
* *
- * functions to handle HTML specific data *
+ * functions to handle HTML specific data *
* *
************************************************************************/
@@ -1085,7 +1174,7 @@ htmlTagLookup(const xmlChar *tag) {
/**
* htmlGetEndPriority:
* @name: The name of the element to look up the priority for.
- *
+ *
* Return value: The "endtag" priority.
**/
static int
@@ -1164,7 +1253,7 @@ htmlAutoCloseOnClose(htmlParserCtxtPtr ctxt, const xmlChar * newtag)
* A missplaced endtag can only close elements with lower
* or equal priority, so if we find an element with higher
* priority before we find an element with
- * matching name, we just ignore this endtag
+ * matching name, we just ignore this endtag
*/
if (htmlGetEndPriority(ctxt->nameTab[i]) > priority)
return;
@@ -1215,7 +1304,7 @@ htmlAutoCloseOnEnd(htmlParserCtxtPtr ctxt)
* called when a new tag has been detected and generates the
* appropriates closes if possible/needed.
* If newtag is NULL this mean we are at the end of the resource
- * and we should check
+ * and we should check
*/
static void
htmlAutoClose(htmlParserCtxtPtr ctxt, const xmlChar * newtag)
@@ -1303,6 +1392,8 @@ htmlIsAutoClosed(htmlDocPtr doc, htmlNodePtr elem) {
*/
static void
htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
+ int i;
+
if (!htmlOmittedDefaultValue)
return;
if (xmlStrEqual(newtag, BAD_CAST"html"))
@@ -1314,24 +1405,31 @@ htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
}
if ((xmlStrEqual(newtag, BAD_CAST"body")) || (xmlStrEqual(newtag, BAD_CAST"head")))
return;
- if ((ctxt->nameNr <= 1) &&
+ if ((ctxt->nameNr <= 1) &&
((xmlStrEqual(newtag, BAD_CAST"script")) ||
(xmlStrEqual(newtag, BAD_CAST"style")) ||
(xmlStrEqual(newtag, BAD_CAST"meta")) ||
(xmlStrEqual(newtag, BAD_CAST"link")) ||
(xmlStrEqual(newtag, BAD_CAST"title")) ||
(xmlStrEqual(newtag, BAD_CAST"base")))) {
- /*
- * dropped OBJECT ... i you put it first BODY will be
- * assumed !
- */
- htmlnamePush(ctxt, BAD_CAST"head");
- if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
- ctxt->sax->startElement(ctxt->userData, BAD_CAST"head", NULL);
+ if (ctxt->html >= 3) {
+ /* we already saw or generated an <head> before */
+ return;
+ }
+ /*
+ * dropped OBJECT ... i you put it first BODY will be
+ * assumed !
+ */
+ htmlnamePush(ctxt, BAD_CAST"head");
+ if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
+ ctxt->sax->startElement(ctxt->userData, BAD_CAST"head", NULL);
} else if ((!xmlStrEqual(newtag, BAD_CAST"noframes")) &&
(!xmlStrEqual(newtag, BAD_CAST"frame")) &&
(!xmlStrEqual(newtag, BAD_CAST"frameset"))) {
- int i;
+ if (ctxt->html >= 10) {
+ /* we already saw or generated a <body> before */
+ return;
+ }
for (i = 0;i < ctxt->nameNr;i++) {
if (xmlStrEqual(ctxt->nameTab[i], BAD_CAST"body")) {
return;
@@ -1340,7 +1438,7 @@ htmlCheckImplied(htmlParserCtxtPtr ctxt, const xmlChar *newtag) {
return;
}
}
-
+
htmlnamePush(ctxt, BAD_CAST"body");
if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
ctxt->sax->startElement(ctxt->userData, BAD_CAST"body", NULL);
@@ -1402,12 +1500,12 @@ htmlIsScriptAttribute(const xmlChar *name) {
unsigned int i;
if (name == NULL)
- return(0);
+ return(0);
/*
* all script attributes start with 'on'
*/
if ((name[0] != 'o') || (name[1] != 'n'))
- return(0);
+ return(0);
for (i = 0;
i < sizeof(htmlScriptAttributes)/sizeof(htmlScriptAttributes[0]);
i++) {
@@ -1419,7 +1517,7 @@ htmlIsScriptAttribute(const xmlChar *name) {
/************************************************************************
* *
- * The list of HTML predefined entities *
+ * The list of HTML predefined entities *
* *
************************************************************************/
@@ -1833,7 +1931,7 @@ UTF8ToHtml(unsigned char* out, int *outlen,
if (inend - in < trailing) {
break;
- }
+ }
for ( ; trailing; trailing--) {
if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80))
@@ -2023,7 +2121,7 @@ htmlNewInputStream(htmlParserCtxtPtr ctxt) {
* *
************************************************************************/
/*
- * all tags allowing pc data from the html 4.01 loose dtd
+ * all tags allowing pc data from the html 4.01 loose dtd
* NOTE: it might be more apropriate to integrate this information
* into the html40ElementTable array but I don't want to risk any
* binary incomptibility
@@ -2083,7 +2181,7 @@ static int areBlanks(htmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
if (lastChild == NULL) {
if ((ctxt->node->type != XML_ELEMENT_NODE) &&
(ctxt->node->content != NULL)) return(0);
- /* keep ws in constructs like ...<b> </b>...
+ /* keep ws in constructs like ...<b> </b>...
for all tags "b" allowing PCDATA */
for ( i = 0; i < sizeof(allowPCData)/sizeof(allowPCData[0]); i++ ) {
if ( xmlStrEqual(ctxt->name, BAD_CAST allowPCData[i]) ) {
@@ -2093,7 +2191,7 @@ static int areBlanks(htmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
} else if (xmlNodeIsText(lastChild)) {
return(0);
} else {
- /* keep ws in constructs like <p><b>xy</b> <i>z</i><p>
+ /* keep ws in constructs like <p><b>xy</b> <i>z</i><p>
for all tags "p" allowing PCDATA */
for ( i = 0; i < sizeof(allowPCData)/sizeof(allowPCData[0]); i++ ) {
if ( xmlStrEqual(lastChild->name, BAD_CAST allowPCData[i]) ) {
@@ -2133,7 +2231,7 @@ htmlNewDocNoDtD(const xmlChar *URI, const xmlChar *ExternalID) {
cur->intSubset = NULL;
cur->doc = cur;
cur->name = NULL;
- cur->children = NULL;
+ cur->children = NULL;
cur->extSubset = NULL;
cur->oldNs = NULL;
cur->encoding = NULL;
@@ -2201,18 +2299,19 @@ htmlParseHTMLName(htmlParserCtxtPtr ctxt) {
xmlChar loc[HTML_PARSER_BUFFER_SIZE];
if (!IS_ASCII_LETTER(CUR) && (CUR != '_') &&
- (CUR != ':')) return(NULL);
+ (CUR != ':') && (CUR != '.')) return(NULL);
while ((i < HTML_PARSER_BUFFER_SIZE) &&
((IS_ASCII_LETTER(CUR)) || (IS_ASCII_DIGIT(CUR)) ||
- (CUR == ':') || (CUR == '-') || (CUR == '_'))) {
+ (CUR == ':') || (CUR == '-') || (CUR == '_') ||
+ (CUR == '.'))) {
if ((CUR >= 'A') && (CUR <= 'Z')) loc[i] = CUR + 0x20;
else loc[i] = CUR;
i++;
-
+
NEXT;
}
-
+
return(xmlDictLookup(ctxt->dict, loc, i));
}
@@ -2235,7 +2334,7 @@ htmlParseHTMLName_nonInvasive(htmlParserCtxtPtr ctxt) {
if (!IS_ASCII_LETTER(NXT(1)) && (NXT(1) != '_') &&
(NXT(1) != ':')) return(NULL);
-
+
while ((i < HTML_PARSER_BUFFER_SIZE) &&
((IS_ASCII_LETTER(NXT(1+i))) || (IS_ASCII_DIGIT(NXT(1+i))) ||
(NXT(1+i) == ':') || (NXT(1+i) == '-') || (NXT(1+i) == '_'))) {
@@ -2243,7 +2342,7 @@ htmlParseHTMLName_nonInvasive(htmlParserCtxtPtr ctxt) {
else loc[i] = NXT(1+i);
i++;
}
-
+
return(xmlDictLookup(ctxt->dict, loc, i));
}
@@ -2311,7 +2410,7 @@ htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(c == '.') || (c == '-') ||
- (c == '_') || (c == ':') ||
+ (c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) {
if (count++ > 100) {
@@ -2330,7 +2429,7 @@ htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
* htmlParseHTMLAttribute:
* @ctxt: an HTML parser context
* @stop: a char stop value
- *
+ *
* parse an HTML attribute value till the stop (quote), if
* stop is 0 then it stops at the first space
*
@@ -2375,13 +2474,13 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) {
{ *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (c < 0x10000)
{ *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
- else
+ else
{ *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
-
+
for ( ; bits >= 0; bits-= 6) {
*out++ = ((c >> bits) & 0x3F) | 0x80;
}
-
+
if (out - buffer > buffer_size - 100) {
int indx = out - buffer;
@@ -2427,9 +2526,9 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) {
{ *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (c < 0x10000)
{ *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
- else
+ else
{ *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
-
+
for ( ; bits >= 0; bits-= 6) {
*out++ = ((c >> bits) & 0x3F) | 0x80;
}
@@ -2452,16 +2551,16 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) {
{ *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (c < 0x10000)
{ *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
- else
+ else
{ *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
-
+
for ( ; bits >= 0; bits-= 6) {
*out++ = ((c >> bits) & 0x3F) | 0x80;
}
NEXT;
}
}
- *out++ = 0;
+ *out = 0;
return(buffer);
}
@@ -2522,7 +2621,7 @@ htmlParseEntityRef(htmlParserCtxtPtr ctxt, const xmlChar **str) {
* parse a value for an attribute
* Note: the parser won't do substitution of entities here, this
* will be handled later in xmlStringGetNodeList, unless it was
- * asked for ctxt->replaceEntities != 0
+ * asked for ctxt->replaceEntities != 0
*
* Returns the AttValue parsed or NULL.
*/
@@ -2563,7 +2662,7 @@ htmlParseAttValue(htmlParserCtxtPtr ctxt) {
/**
* htmlParseSystemLiteral:
* @ctxt: an HTML parser context
- *
+ *
* parse an HTML Literal
*
* [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
@@ -2604,7 +2703,7 @@ htmlParseSystemLiteral(htmlParserCtxtPtr ctxt) {
htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,
" or ' expected\n", NULL, NULL);
}
-
+
return(ret);
}
@@ -2653,7 +2752,7 @@ htmlParsePubidLiteral(htmlParserCtxtPtr ctxt) {
htmlParseErr(ctxt, XML_ERR_LITERAL_NOT_STARTED,
"PubidLiteral \" or ' expected\n", NULL, NULL);
}
-
+
return(ret);
}
@@ -2700,8 +2799,8 @@ htmlParseScript(htmlParserCtxtPtr ctxt) {
* CDATA.
*/
if (ctxt->recovery) {
- if (xmlStrncasecmp(ctxt->name, ctxt->input->cur+2,
- xmlStrlen(ctxt->name)) == 0)
+ if (xmlStrncasecmp(ctxt->name, ctxt->input->cur+2,
+ xmlStrlen(ctxt->name)) == 0)
{
break; /* while */
} else {
@@ -2711,7 +2810,7 @@ htmlParseScript(htmlParserCtxtPtr ctxt) {
}
} else {
if (((NXT(2) >= 'A') && (NXT(2) <= 'Z')) ||
- ((NXT(2) >= 'a') && (NXT(2) <= 'z')))
+ ((NXT(2) >= 'a') && (NXT(2) <= 'z')))
{
break; /* while */
}
@@ -2773,7 +2872,7 @@ htmlParseCharData(htmlParserCtxtPtr ctxt) {
SHRINK;
cur = CUR_CHAR(l);
while (((cur != '<') || (ctxt->token == '<')) &&
- ((cur != '&') || (ctxt->token == '&')) &&
+ ((cur != '&') || (ctxt->token == '&')) &&
(cur != 0)) {
if (!(IS_CHAR(cur))) {
htmlParseErrInt(ctxt, XML_ERR_INVALID_CHAR,
@@ -2999,7 +3098,7 @@ htmlParsePI(htmlParserCtxtPtr ctxt) {
}
xmlFree(buf);
} else {
- htmlParseErr(ctxt, XML_ERR_PI_NOT_STARTED,
+ htmlParseErr(ctxt, XML_ERR_PI_NOT_STARTED,
"PI is not started correctly", NULL, NULL);
}
ctxt->instate = state;
@@ -3115,7 +3214,7 @@ htmlParseCharRef(htmlParserCtxtPtr ctxt) {
((NXT(2) == 'x') || NXT(2) == 'X')) {
SKIP(3);
while (CUR != ';') {
- if ((CUR >= '0') && (CUR <= '9'))
+ if ((CUR >= '0') && (CUR <= '9'))
val = val * 16 + (CUR - '0');
else if ((CUR >= 'a') && (CUR <= 'f'))
val = val * 16 + (CUR - 'a') + 10;
@@ -3134,7 +3233,7 @@ htmlParseCharRef(htmlParserCtxtPtr ctxt) {
} else if ((CUR == '&') && (NXT(1) == '#')) {
SKIP(2);
while (CUR != ';') {
- if ((CUR >= '0') && (CUR <= '9'))
+ if ((CUR >= '0') && (CUR <= '9'))
val = val * 10 + (CUR - '0');
else {
htmlParseErr(ctxt, XML_ERR_INVALID_DEC_CHARREF,
@@ -3170,7 +3269,7 @@ htmlParseCharRef(htmlParserCtxtPtr ctxt) {
*
* parse a DOCTYPE declaration
*
- * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
+ * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
* ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
*/
@@ -3302,7 +3401,7 @@ htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
if ((ctxt == NULL) || (attvalue == NULL))
return;
- /* do not change encoding */
+ /* do not change encoding */
if (ctxt->input->encoding != NULL)
return;
@@ -3329,7 +3428,7 @@ htmlCheckEncoding(htmlParserCtxtPtr ctxt, const xmlChar *attvalue) {
* registered set of known encodings
*/
if (enc != XML_CHAR_ENCODING_ERROR) {
- if (((enc == XML_CHAR_ENCODING_UTF16LE) ||
+ if (((enc == XML_CHAR_ENCODING_UTF16LE) ||
(enc == XML_CHAR_ENCODING_UTF16BE) ||
(enc == XML_CHAR_ENCODING_UCS4LE) ||
(enc == XML_CHAR_ENCODING_UCS4BE)) &&
@@ -3417,7 +3516,7 @@ htmlCheckMeta(htmlParserCtxtPtr ctxt, const xmlChar **atts) {
/**
* htmlParseStartTag:
* @ctxt: an HTML parser context
- *
+ *
* parse a start of tag either for rule element or
* EmptyElement. In both case we don't parse the tag closing chars.
*
@@ -3446,6 +3545,8 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
int i;
int discardtag = 0;
+ if (ctxt->instate == XML_PARSER_EOF)
+ return(-1);
if ((ctxt == NULL) || (ctxt->input == NULL)) {
htmlParseErr(ctxt, XML_ERR_INTERNAL_ERROR,
"htmlParseStartTag: context error\n", NULL, NULL);
@@ -3464,7 +3565,8 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
"htmlParseStartTag: invalid element name\n",
NULL, NULL);
/* Dump the bogus tag like browsers do */
- while ((IS_CHAR_CH(CUR)) && (CUR != '>'))
+ while ((IS_CHAR_CH(CUR)) && (CUR != '>') &&
+ (ctxt->instate != XML_PARSER_EOF))
NEXT;
return -1;
}
@@ -3492,7 +3594,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
discardtag = 1;
ctxt->depth++;
}
- if ((ctxt->nameNr != 1) &&
+ if ((ctxt->nameNr != 1) &&
(xmlStrEqual(name, BAD_CAST"head"))) {
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"htmlParseStartTag: misplaced <head> tag\n",
@@ -3520,7 +3622,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) {
*/
SKIP_BLANKS;
while ((IS_CHAR_CH(CUR)) &&
- (CUR != '>') &&
+ (CUR != '>') &&
((CUR != '/') || (NXT(1) != '>'))) {
long cons = ctxt->nbChars;
@@ -3744,7 +3846,7 @@ htmlParseEndTag(htmlParserCtxtPtr ctxt)
/**
* htmlParseReference:
* @ctxt: an HTML parser context
- *
+ *
* parse and handle entity references in content,
* this will end-up in a call to character() since this is either a
* CharRef, or a predefined entity.
@@ -3768,7 +3870,7 @@ htmlParseReference(htmlParserCtxtPtr ctxt) {
else if (c < 0x800) { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (c < 0x10000) { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
else { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
-
+
for ( ; bits >= 0; bits-= 6) {
out[i++]= ((c >> bits) & 0x3F) | 0x80;
}
@@ -3803,9 +3905,9 @@ htmlParseReference(htmlParserCtxtPtr ctxt) {
{ out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
else if (c < 0x10000)
{ out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
- else
+ else
{ out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
-
+
for ( ; bits >= 0; bits-= 6) {
out[i++]= ((c >> bits) & 0x3F) | 0x80;
}
@@ -3837,6 +3939,10 @@ htmlParseContent(htmlParserCtxtPtr ctxt) {
long cons = ctxt->nbChars;
GROW;
+
+ if (ctxt->instate == XML_PARSER_EOF)
+ break;
+
/*
* Our tag or one of it's parent or children is ending.
*/
@@ -3859,7 +3965,7 @@ htmlParseContent(htmlParserCtxtPtr ctxt) {
"htmlParseStartTag: invalid element name\n",
NULL, NULL);
/* Dump the bogus tag like browsers do */
- while ((IS_CHAR_CH(CUR)) && (CUR != '>'))
+ while ((IS_CHAR_CH(CUR)) && (CUR != '>'))
NEXT;
if (currentNode != NULL)
@@ -3872,7 +3978,7 @@ htmlParseContent(htmlParserCtxtPtr ctxt) {
htmlAutoClose(ctxt, name);
continue;
}
- }
+ }
}
/*
@@ -3931,7 +4037,7 @@ htmlParseContent(htmlParserCtxtPtr ctxt) {
/*
* Fourth case : a reference. If if has not been resolved,
- * parsing returns it's Name, create the node
+ * parsing returns it's Name, create the node
*/
else if (CUR == '&') {
htmlParseReference(ctxt);
@@ -4005,6 +4111,10 @@ htmlParseElement(htmlParserCtxtPtr ctxt) {
"htmlParseElement: context error\n", NULL, NULL);
return;
}
+
+ if (ctxt->instate == XML_PARSER_EOF)
+ return;
+
/* Capture start position */
if (ctxt->record_info) {
node_info.begin_pos = ctxt->input->consumed +
@@ -4049,10 +4159,10 @@ htmlParseElement(htmlParserCtxtPtr ctxt) {
/*
* end of parsing of this node.
*/
- if (xmlStrEqual(name, ctxt->name)) {
+ if (xmlStrEqual(name, ctxt->name)) {
nodePop(ctxt);
htmlnamePop(ctxt);
- }
+ }
/*
* Capture end position and add node
@@ -4086,8 +4196,8 @@ htmlParseElement(htmlParserCtxtPtr ctxt) {
oldptr = ctxt->input->cur;
htmlParseContent(ctxt);
if (oldptr==ctxt->input->cur) break;
- if (ctxt->nameNr < depth) break;
- }
+ if (ctxt->nameNr < depth) break;
+ }
/*
* Capture end position and add node
@@ -4110,7 +4220,7 @@ htmlParseElement(htmlParserCtxtPtr ctxt) {
/**
* htmlParseDocument:
* @ctxt: an HTML parser context
- *
+ *
* parse an HTML document (and build a tree if using the standard SAX
* interface).
*
@@ -4134,6 +4244,7 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
return(XML_ERR_INTERNAL_ERROR);
}
ctxt->html = 1;
+ ctxt->linenumbers = 1;
GROW;
/*
* SAX: beginning of the document processing.
@@ -4163,7 +4274,7 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
*/
SKIP_BLANKS;
if (CUR == 0) {
- htmlParseErr(ctxt, XML_ERR_DOCUMENT_EMPTY,
+ htmlParseErr(ctxt, XML_ERR_DOCUMENT_EMPTY,
"Document is empty\n", NULL, NULL);
}
@@ -4202,10 +4313,10 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
while (((CUR == '<') && (NXT(1) == '!') &&
(NXT(2) == '-') && (NXT(3) == '-')) ||
((CUR == '<') && (NXT(1) == '?'))) {
- htmlParseComment(ctxt);
- htmlParsePI(ctxt);
+ htmlParseComment(ctxt);
+ htmlParsePI(ctxt);
SKIP_BLANKS;
- }
+ }
/*
* Time to start parsing the tree itself
@@ -4228,8 +4339,8 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {
if (ctxt->myDoc != NULL) {
dtd = xmlGetIntSubset(ctxt->myDoc);
if (dtd == NULL)
- ctxt->myDoc->intSubset =
- xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
+ 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");
}
@@ -4275,7 +4386,7 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
memset(sax, 0, sizeof(htmlSAXHandler));
/* Allocate the Input stack */
- ctxt->inputTab = (htmlParserInputPtr *)
+ ctxt->inputTab = (htmlParserInputPtr *)
xmlMalloc(5 * sizeof(htmlParserInputPtr));
if (ctxt->inputTab == NULL) {
htmlErrMemory(NULL, "htmlInitParserCtxt: out of memory\n");
@@ -4473,7 +4584,7 @@ htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) {
xmlSwitchEncoding(ctxt, enc);
if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
htmlParseErr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
- "Unsupported encoding %s\n",
+ "Unsupported encoding %s\n",
(const xmlChar *) encoding, NULL);
}
} else {
@@ -4496,7 +4607,7 @@ htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) {
#ifdef LIBXML_PUSH_ENABLED
/************************************************************************
* *
- * Progressive parsing interfaces *
+ * Progressive parsing interfaces *
* *
************************************************************************/
@@ -4520,85 +4631,190 @@ htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) {
*/
static int
htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first,
- xmlChar next, xmlChar third, int iscomment) {
+ xmlChar next, xmlChar third, int iscomment,
+ int ignoreattrval)
+{
int base, len;
htmlParserInputPtr in;
const xmlChar *buf;
int incomment = 0;
+ int invalue = 0;
+ char valdellim = 0x0;
in = ctxt->input;
- if (in == NULL) return(-1);
+ if (in == NULL)
+ return (-1);
+
base = in->cur - in->base;
- if (base < 0) return(-1);
+ if (base < 0)
+ return (-1);
+
if (ctxt->checkIndex > base)
base = ctxt->checkIndex;
+
if (in->buf == NULL) {
- buf = in->base;
- len = in->length;
+ buf = in->base;
+ len = in->length;
} else {
- buf = in->buf->buffer->content;
- len = in->buf->buffer->use;
+ buf = in->buf->buffer->content;
+ len = in->buf->buffer->use;
}
+
/* take into account the sequence length */
- if (third) len -= 2;
- else if (next) len --;
- for (;base < len;base++) {
- if (!incomment && (base + 4 < len) && !iscomment) {
- if ((buf[base] == '<') && (buf[base + 1] == '!') &&
- (buf[base + 2] == '-') && (buf[base + 3] == '-')) {
- incomment = 1;
- /* do not increment past <! - some people use <!--> */
- base += 2;
- }
- }
- if (incomment) {
- if (base + 3 > len)
- return(-1);
- if ((buf[base] == '-') && (buf[base + 1] == '-') &&
- (buf[base + 2] == '>')) {
- incomment = 0;
- base += 2;
- }
- continue;
- }
+ if (third)
+ len -= 2;
+ else if (next)
+ len--;
+ for (; base < len; base++) {
+ if ((!incomment) && (base + 4 < len) && (!iscomment)) {
+ if ((buf[base] == '<') && (buf[base + 1] == '!') &&
+ (buf[base + 2] == '-') && (buf[base + 3] == '-')) {
+ incomment = 1;
+ /* do not increment past <! - some people use <!--> */
+ base += 2;
+ }
+ }
+ if (ignoreattrval) {
+ if (buf[base] == '"' || buf[base] == '\'') {
+ if (invalue) {
+ if (buf[base] == valdellim) {
+ invalue = 0;
+ continue;
+ }
+ } else {
+ valdellim = buf[base];
+ invalue = 1;
+ continue;
+ }
+ } else if (invalue) {
+ continue;
+ }
+ }
+ if (incomment) {
+ if (base + 3 > len)
+ return (-1);
+ if ((buf[base] == '-') && (buf[base + 1] == '-') &&
+ (buf[base + 2] == '>')) {
+ incomment = 0;
+ base += 2;
+ }
+ continue;
+ }
if (buf[base] == first) {
- if (third != 0) {
- if ((buf[base + 1] != next) ||
- (buf[base + 2] != third)) continue;
- } else if (next != 0) {
- if (buf[base + 1] != next) continue;
- }
- ctxt->checkIndex = 0;
+ if (third != 0) {
+ if ((buf[base + 1] != next) || (buf[base + 2] != third))
+ continue;
+ } else if (next != 0) {
+ if (buf[base + 1] != next)
+ continue;
+ }
+ ctxt->checkIndex = 0;
#ifdef DEBUG_PUSH
- if (next == 0)
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c' found at %d\n",
- first, base);
- else if (third == 0)
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c%c' found at %d\n",
- first, next, base);
- else
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c%c%c' found at %d\n",
- first, next, third, base);
+ if (next == 0)
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c' found at %d\n",
+ first, base);
+ else if (third == 0)
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c%c' found at %d\n",
+ first, next, base);
+ else
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c%c%c' found at %d\n",
+ first, next, third, base);
#endif
- return(base - (in->cur - in->base));
- }
+ return (base - (in->cur - in->base));
+ }
}
- ctxt->checkIndex = base;
+ if ((!incomment) && (!invalue))
+ ctxt->checkIndex = base;
#ifdef DEBUG_PUSH
if (next == 0)
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c' failed\n", first);
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c' failed\n", first);
else if (third == 0)
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c%c' failed\n", first, next);
- else
- xmlGenericError(xmlGenericErrorContext,
- "HPP: lookup '%c%c%c' failed\n", first, next, third);
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c%c' failed\n", first, next);
+ else
+ xmlGenericError(xmlGenericErrorContext,
+ "HPP: lookup '%c%c%c' failed\n", first, next,
+ third);
#endif
- return(-1);
+ return (-1);
+}
+
+/**
+ * htmlParseLookupChars:
+ * @ctxt: an HTML parser context
+ * @stop: Array of chars, which stop the lookup.
+ * @stopLen: Length of stop-Array
+ *
+ * Try to find if any char of the stop-Array is available in the input
+ * stream.
+ * This function has a side effect of (possibly) incrementing ctxt->checkIndex
+ * to avoid rescanning sequences of bytes, it DOES change the state of the
+ * parser, do not use liberally.
+ *
+ * Returns the index to the current parsing point if a stopChar
+ * is available, -1 otherwise.
+ */
+static int
+htmlParseLookupChars(htmlParserCtxtPtr ctxt, const xmlChar * stop,
+ int stopLen)
+{
+ int base, len;
+ htmlParserInputPtr in;
+ const xmlChar *buf;
+ int incomment = 0;
+ int i;
+
+ in = ctxt->input;
+ if (in == NULL)
+ return (-1);
+
+ base = in->cur - in->base;
+ if (base < 0)
+ return (-1);
+
+ if (ctxt->checkIndex > base)
+ base = ctxt->checkIndex;
+
+ if (in->buf == NULL) {
+ buf = in->base;
+ len = in->length;
+ } else {
+ buf = in->buf->buffer->content;
+ len = in->buf->buffer->use;
+ }
+
+ for (; base < len; base++) {
+ if (!incomment && (base + 4 < len)) {
+ if ((buf[base] == '<') && (buf[base + 1] == '!') &&
+ (buf[base + 2] == '-') && (buf[base + 3] == '-')) {
+ incomment = 1;
+ /* do not increment past <! - some people use <!--> */
+ base += 2;
+ }
+ }
+ if (incomment) {
+ if (base + 3 > len)
+ return (-1);
+ if ((buf[base] == '-') && (buf[base + 1] == '-') &&
+ (buf[base + 2] == '>')) {
+ incomment = 0;
+ base += 2;
+ }
+ continue;
+ }
+ for (i = 0; i < stopLen; ++i) {
+ if (buf[base] == stop[i]) {
+ ctxt->checkIndex = 0;
+ return (base - (in->cur - in->base));
+ }
+ }
+ }
+ ctxt->checkIndex = base;
+ return (-1);
}
/**
@@ -4680,7 +4896,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
avail = in->buf->buffer->use - (in->cur - in->base);
if ((avail == 0) && (terminate)) {
htmlAutoCloseOnEnd(ctxt);
- if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
+ if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
/*
* SAX: end of the document processing.
*/
@@ -4730,7 +4946,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4763,7 +4979,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
if ((cur == '<') && (next == '!') &&
(in->cur[2] == '-') && (in->cur[3] == '-')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '-', '-', '>', 1) < 0))
+ (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4773,7 +4989,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
ctxt->instate = XML_PARSER_MISC;
} else if ((cur == '<') && (next == '?')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4787,7 +5003,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4816,14 +5032,14 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
avail = in->length - (in->cur - in->base);
else
avail = in->buf->buffer->use - (in->cur - in->base);
- if (avail < 2)
+ if (avail < 2)
goto done;
cur = in->cur[0];
next = in->cur[1];
if ((cur == '<') && (next == '!') &&
(in->cur[2] == '-') && (in->cur[3] == '-')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '-', '-', '>', 1) < 0))
+ (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4833,7 +5049,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
ctxt->instate = XML_PARSER_PROLOG;
} else if ((cur == '<') && (next == '?')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4870,7 +5086,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
if ((cur == '<') && (next == '!') &&
(in->cur[2] == '-') && (in->cur[3] == '-')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '-', '-', '>', 1) < 0))
+ (htmlParseLookupSequence(ctxt, '-', '-', '>', 1, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4880,7 +5096,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
ctxt->instate = XML_PARSER_EPILOG;
} else if ((cur == '<') && (next == '?')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -4930,7 +5146,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
break;
}
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
failed = htmlParseStartTag(ctxt);
@@ -4977,10 +5193,10 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
/*
* end of parsing of this node.
*/
- if (xmlStrEqual(name, ctxt->name)) {
+ if (xmlStrEqual(name, ctxt->name)) {
nodePop(ctxt);
htmlnamePop(ctxt);
- }
+ }
ctxt->instate = XML_PARSER_CONTENT;
#ifdef DEBUG_PUSH
@@ -5055,7 +5271,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
int idx;
xmlChar val;
- idx = htmlParseLookupSequence(ctxt, '<', '/', 0, 0);
+ idx = htmlParseLookupSequence(ctxt, '<', '/', 0, 0, 1);
if (idx < 0)
goto done;
val = in->cur[idx + 2];
@@ -5082,7 +5298,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"Misplaced DOCTYPE declaration\n",
@@ -5092,7 +5308,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
(in->cur[2] == '-') && (in->cur[3] == '-')) {
if ((!terminate) &&
(htmlParseLookupSequence(
- ctxt, '-', '-', '>', 1) < 0))
+ ctxt, '-', '-', '>', 1, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -5102,7 +5318,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
ctxt->instate = XML_PARSER_CONTENT;
} else if ((cur == '<') && (next == '?')) {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -5130,7 +5346,8 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
break;
} else if (cur == '&') {
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, ';', 0, 0, 0) < 0))
+ (htmlParseLookupChars(ctxt,
+ BAD_CAST "; >/", 4) < 0))
goto done;
#ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext,
@@ -5146,7 +5363,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
* data detection.
*/
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '<', 0, 0, 0) < 0))
+ (htmlParseLookupChars(ctxt, BAD_CAST "<&", 2) < 0))
goto done;
ctxt->checkIndex = 0;
#ifdef DEBUG_PUSH
@@ -5172,7 +5389,7 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
if (avail < 2)
goto done;
if ((!terminate) &&
- (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
+ (htmlParseLookupSequence(ctxt, '>', 0, 0, 0, 1) < 0))
goto done;
htmlParseEndTag(ctxt);
if (ctxt->nameNr == 0) {
@@ -5299,10 +5516,10 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
}
}
-done:
+done:
if ((avail == 0) && (terminate)) {
htmlAutoCloseOnEnd(ctxt);
- if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
+ if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
/*
* SAX: end of the document processing.
*/
@@ -5317,8 +5534,8 @@ done:
xmlDtdPtr dtd;
dtd = xmlGetIntSubset(ctxt->myDoc);
if (dtd == NULL)
- ctxt->myDoc->intSubset =
- xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "html",
+ 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");
}
@@ -5352,8 +5569,8 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
int base = ctxt->input->base - ctxt->input->buf->buffer->content;
int cur = ctxt->input->cur - ctxt->input->base;
int res;
-
- res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
+
+ res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
if (res < 0) {
ctxt->errNo = XML_PARSER_EOF;
ctxt->disableSAX = 1;
@@ -5377,7 +5594,7 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
if ((in->encoder != NULL) && (in->buffer != NULL) &&
(in->raw != NULL)) {
int nbchars;
-
+
nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);
if (nbchars < 0) {
htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING,
@@ -5394,14 +5611,14 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
(ctxt->instate != XML_PARSER_MISC)) {
ctxt->errNo = XML_ERR_DOCUMENT_END;
ctxt->wellFormed = 0;
- }
+ }
if (ctxt->instate != XML_PARSER_EOF) {
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
ctxt->sax->endDocument(ctxt->userData);
}
ctxt->instate = XML_PARSER_EOF;
}
- return((xmlParserErrors) ctxt->errNo);
+ return((xmlParserErrors) ctxt->errNo);
}
/************************************************************************
@@ -5426,7 +5643,7 @@ htmlParseChunk(htmlParserCtxtPtr ctxt, const char *chunk, int size,
* Returns the new parser context or NULL
*/
htmlParserCtxtPtr
-htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
+htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
const char *chunk, int size, const char *filename,
xmlCharEncoding enc) {
htmlParserCtxtPtr ctxt;
@@ -5457,7 +5674,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
memcpy(ctxt->sax, sax, sizeof(htmlSAXHandler));
if (user_data != NULL)
ctxt->userData = user_data;
- }
+ }
if (filename == NULL) {
ctxt->directory = NULL;
} else {
@@ -5479,17 +5696,17 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
inputStream->buf = buf;
inputStream->base = inputStream->buf->buffer->content;
inputStream->cur = inputStream->buf->buffer->content;
- inputStream->end =
+ inputStream->end =
&inputStream->buf->buffer->content[inputStream->buf->buffer->use];
inputPush(ctxt, inputStream);
if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
- (ctxt->input->buf != NULL)) {
+ (ctxt->input->buf != NULL)) {
int base = ctxt->input->base - ctxt->input->buf->buffer->content;
int cur = ctxt->input->cur - ctxt->input->base;
- xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
+ xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
ctxt->input->base = ctxt->input->buf->buffer->content + base;
ctxt->input->cur = ctxt->input->base + cur;
@@ -5510,12 +5727,12 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
* @cur: a pointer to an array of xmlChar
* @encoding: a free form C string describing the HTML document encoding, or NULL
* @sax: the SAX handler block
- * @userData: if using SAX, this pointer will be provided on callbacks.
+ * @userData: if using SAX, this pointer will be provided on callbacks.
*
* Parse an HTML in-memory document. If sax is not NULL, use the SAX callbacks
* to handle parse events. If sax is NULL, fallback to the default DOM
* behavior and return a tree.
- *
+ *
* Returns the resulting document tree unless SAX is NULL or the document is
* not well formed.
*/
@@ -5532,7 +5749,7 @@ htmlSAXParseDoc(xmlChar *cur, const char *encoding, htmlSAXHandlerPtr sax, void
ctxt = htmlCreateDocParserCtxt(cur, encoding);
if (ctxt == NULL) return(NULL);
- if (sax != NULL) {
+ if (sax != NULL) {
if (ctxt->sax != NULL) xmlFree (ctxt->sax);
ctxt->sax = sax;
ctxt->userData = userData;
@@ -5545,7 +5762,7 @@ htmlSAXParseDoc(xmlChar *cur, const char *encoding, htmlSAXHandlerPtr sax, void
ctxt->userData = NULL;
}
htmlFreeParserCtxt(ctxt);
-
+
return(ret);
}
@@ -5555,7 +5772,7 @@ htmlSAXParseDoc(xmlChar *cur, const char *encoding, htmlSAXHandlerPtr sax, void
* @encoding: a free form C string describing the HTML document encoding, or NULL
*
* parse an HTML in-memory document and build a tree.
- *
+ *
* Returns the resulting document tree
*/
@@ -5570,7 +5787,7 @@ htmlParseDoc(xmlChar *cur, const char *encoding) {
* @filename: the filename
* @encoding: a free form C string describing the HTML document encoding, or NULL
*
- * Create a parser context for a file content.
+ * Create a parser context for a file content.
* Automatic support for ZLIB/Compress compressed document is provided
* by default if found at compile-time.
*
@@ -5602,7 +5819,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
xmlFreeParserCtxt(ctxt);
return(NULL);
}
-
+
inputStream = xmlLoadExternalEntity(canonicFilename, NULL, ctxt);
xmlFree(canonicFilename);
if (inputStream == NULL) {
@@ -5615,14 +5832,14 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
/* set encoding */
if (encoding) {
content = xmlMallocAtomic (xmlStrlen(content_line) + strlen(encoding) + 1);
- if (content) {
+ if (content) {
strcpy ((char *)content, (char *)content_line);
strcat ((char *)content, (char *)encoding);
htmlCheckEncoding (ctxt, content);
xmlFree (content);
}
}
-
+
return(ctxt);
}
@@ -5631,7 +5848,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
* @filename: the filename
* @encoding: a free form C string describing the HTML document encoding, or NULL
* @sax: the SAX handler block
- * @userData: if using SAX, this pointer will be provided on callbacks.
+ * @userData: if using SAX, this pointer will be provided on callbacks.
*
* parse an HTML file and build a tree. Automatic support for ZLIB/Compress
* compressed document is provided by default if found at compile-time.
@@ -5643,7 +5860,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding)
*/
htmlDocPtr
-htmlSAXParseFile(const char *filename, const char *encoding, htmlSAXHandlerPtr sax,
+htmlSAXParseFile(const char *filename, const char *encoding, htmlSAXHandlerPtr sax,
void *userData) {
htmlDocPtr ret;
htmlParserCtxtPtr ctxt;
@@ -5667,7 +5884,7 @@ htmlSAXParseFile(const char *filename, const char *encoding, htmlSAXHandlerPtr s
ctxt->userData = NULL;
}
htmlFreeParserCtxt(ctxt);
-
+
return(ret);
}
@@ -5689,7 +5906,7 @@ htmlParseFile(const char *filename, const char *encoding) {
/**
* htmlHandleOmittedElem:
- * @val: int 0 or 1
+ * @val: int 0 or 1
*
* Set and return the previous value for handling HTML omitted tags.
*
@@ -5829,7 +6046,7 @@ htmlNodeStatus(const htmlNodePtr node, int legacy) {
* current scope
*/
#define DICT_FREE(str) \
- if ((str) && ((!dict) || \
+ if ((str) && ((!dict) || \
(xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
xmlFree((char *)(str));
@@ -5844,7 +6061,7 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt)
{
xmlParserInputPtr input;
xmlDictPtr dict;
-
+
if (ctxt == NULL)
return;
@@ -5971,6 +6188,10 @@ htmlCtxtUseOptions(htmlParserCtxtPtr ctxt, int options)
ctxt->options |= HTML_PARSE_COMPACT;
options -= HTML_PARSE_COMPACT;
}
+ if (options & XML_PARSE_HUGE) {
+ ctxt->options |= XML_PARSE_HUGE;
+ options -= XML_PARSE_HUGE;
+ }
ctxt->dictNames = 0;
return (options);
}
@@ -5984,7 +6205,7 @@ htmlCtxtUseOptions(htmlParserCtxtPtr ctxt, int options)
* @reuse: keep the context for reuse
*
* Common front-end for the htmlRead functions
- *
+ *
* Returns the resulting document tree or NULL
*/
static htmlDocPtr
@@ -5992,7 +6213,7 @@ htmlDoRead(htmlParserCtxtPtr ctxt, const char *URL, const char *encoding,
int options, int reuse)
{
htmlDocPtr ret;
-
+
htmlCtxtUseOptions(ctxt, options);
ctxt->html = 1;
if (encoding != NULL) {
@@ -6030,7 +6251,7 @@ htmlDoRead(htmlParserCtxtPtr ctxt, const char *URL, const char *encoding,
* @options: a combination of htmlParserOption(s)
*
* parse an XML in-memory document and build a tree.
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6055,7 +6276,7 @@ htmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int opti
* @options: a combination of htmlParserOption(s)
*
* parse an XML file from the filesystem or the network.
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6079,7 +6300,7 @@ htmlReadFile(const char *filename, const char *encoding, int options)
* @options: a combination of htmlParserOption(s)
*
* parse an XML in-memory document and build a tree.
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6105,7 +6326,7 @@ htmlReadMemory(const char *buffer, int size, const char *URL, const char *encodi
* @options: a combination of htmlParserOption(s)
*
* parse an XML from a file descriptor and build a tree.
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6147,7 +6368,7 @@ htmlReadFd(int fd, const char *URL, const char *encoding, int options)
* @options: a combination of htmlParserOption(s)
*
* parse an HTML document from I/O functions and source and build a tree.
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6191,7 +6412,7 @@ htmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
*
* parse an XML in-memory document and build a tree.
* This reuses the existing @ctxt parser context
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6224,7 +6445,7 @@ htmlCtxtReadDoc(htmlParserCtxtPtr ctxt, const xmlChar * cur,
*
* parse an XML file from the filesystem or the network.
* This reuses the existing @ctxt parser context
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6259,7 +6480,7 @@ htmlCtxtReadFile(htmlParserCtxtPtr ctxt, const char *filename,
*
* parse an XML in-memory document and build a tree.
* This reuses the existing @ctxt parser context
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6301,7 +6522,7 @@ htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,
*
* parse an XML from a file descriptor and build a tree.
* This reuses the existing @ctxt parser context
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr
@@ -6343,7 +6564,7 @@ htmlCtxtReadFd(htmlParserCtxtPtr ctxt, int fd,
*
* parse an HTML document from I/O functions and source and build a tree.
* This reuses the existing @ctxt parser context
- *
+ *
* Returns the resulting document tree
*/
htmlDocPtr