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

fixed bug #102960 by reusing the XML name parsing routines. Daniel

* HTMLparser.c: fixed bug #102960 by reusing the XML name parsing
  routines.
Daniel
This commit is contained in:
Daniel Veillard
2003-01-10 12:50:02 +00:00
parent 98d071d878
commit e55e8e4833
2 changed files with 106 additions and 20 deletions

View File

@ -1,3 +1,8 @@
Fri Jan 10 13:47:55 CET 2003 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c: fixed bug #102960 by reusing the XML name parsing
routines.
Fri Jan 10 00:16:49 CET 2003 Daniel Veillard <daniel@veillard.com> Fri Jan 10 00:16:49 CET 2003 Daniel Veillard <daniel@veillard.com>
* parser.c: one more IsEmptyElement crazyness, that time in * parser.c: one more IsEmptyElement crazyness, that time in

View File

@ -1831,6 +1831,8 @@ htmlNewDoc(const xmlChar *URI, const xmlChar *ExternalID) {
* * * *
************************************************************************/ ************************************************************************/
static xmlChar * htmlParseNameComplex(xmlParserCtxtPtr ctxt);
/** /**
* htmlParseHTMLName: * htmlParseHTMLName:
* @ctxt: an HTML parser context * @ctxt: an HTML parser context
@ -1876,36 +1878,115 @@ htmlParseHTMLName(htmlParserCtxtPtr ctxt) {
static xmlChar * static xmlChar *
htmlParseName(htmlParserCtxtPtr ctxt) { htmlParseName(htmlParserCtxtPtr ctxt) {
xmlChar buf[HTML_MAX_NAMELEN]; const xmlChar *in;
int len = 0; xmlChar *ret;
int count = 0;
GROW; GROW;
if (!IS_LETTER(CUR) && (CUR != '_')) {
/*
* Accelerator for simple ASCII names
*/
in = ctxt->input->cur;
if (((*in >= 0x61) && (*in <= 0x7A)) ||
((*in >= 0x41) && (*in <= 0x5A)) ||
(*in == '_') || (*in == ':')) {
in++;
while (((*in >= 0x61) && (*in <= 0x7A)) ||
((*in >= 0x41) && (*in <= 0x5A)) ||
((*in >= 0x30) && (*in <= 0x39)) ||
(*in == '_') || (*in == '-') ||
(*in == ':') || (*in == '.'))
in++;
if ((*in > 0) && (*in < 0x80)) {
count = in - ctxt->input->cur;
ret = xmlStrndup(ctxt->input->cur, count);
ctxt->input->cur = in;
return(ret);
}
}
return(htmlParseNameComplex(ctxt));
}
static xmlChar *
htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
xmlChar buf[XML_MAX_NAMELEN + 5];
int len = 0, l;
int c;
int count = 0;
/*
* Handler for more complex cases
*/
GROW;
c = CUR_CHAR(l);
if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
(c != ':'))) {
return(NULL); return(NULL);
} }
while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
(CUR == '.') || (CUR == '-') || ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(CUR == '_') || (CUR == ':') || (c == '.') || (c == '-') ||
(IS_COMBINING(CUR)) || (c == '_') || (c == ':') ||
(IS_EXTENDER(CUR))) { (IS_COMBINING(c)) ||
buf[len++] = CUR; (IS_EXTENDER(c)))) {
NEXT; if (count++ > 100) {
if (len >= HTML_MAX_NAMELEN) { count = 0;
xmlGenericError(xmlGenericErrorContext, GROW;
"htmlParseName: reached HTML_MAX_NAMELEN limit\n"); }
while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || COPY_BUF(l,buf,len,c);
(CUR == '.') || (CUR == '-') || NEXTL(l);
(CUR == '_') || (CUR == ':') || c = CUR_CHAR(l);
(IS_COMBINING(CUR)) || if (len >= XML_MAX_NAMELEN) {
(IS_EXTENDER(CUR))) /*
NEXT; * Okay someone managed to make a huge name, so he's ready to pay
break; * for the processing speed.
*/
xmlChar *buffer;
int max = len * 2;
buffer = (xmlChar *) xmlMalloc(max * sizeof(xmlChar));
if (buffer == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"htmlParseNameComplex: out of memory\n");
return(NULL);
}
memcpy(buffer, buf, len);
while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigname.xml */
(c == '.') || (c == '-') ||
(c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c))) {
if (count++ > 100) {
count = 0;
GROW;
}
if (len + 10 > max) {
max *= 2;
buffer = (xmlChar *) xmlRealloc(buffer,
max * sizeof(xmlChar));
if (buffer == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"htmlParseNameComplex: out of memory\n");
return(NULL);
}
}
COPY_BUF(l,buffer,len,c);
NEXTL(l);
c = CUR_CHAR(l);
}
buffer[len] = 0;
return(buffer);
} }
} }
return(xmlStrndup(buf, len)); return(xmlStrndup(buf, len));
} }
/** /**
* htmlParseHTMLAttribute: * htmlParseHTMLAttribute:
* @ctxt: an HTML parser context * @ctxt: an HTML parser context