mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-25 23:21:26 +03:00
parser: More fixes to push parser error handling
This commit is contained in:
parent
bbd918b2e7
commit
53050b1dd8
39
parser.c
39
parser.c
@ -10955,7 +10955,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
/*
|
||||
* Very first chars read from the document flow.
|
||||
*/
|
||||
if (avail < 4)
|
||||
if ((!terminate) && (avail < 4))
|
||||
goto done;
|
||||
|
||||
/*
|
||||
@ -10973,23 +10973,12 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
break;
|
||||
|
||||
case XML_PARSER_XML_DECL:
|
||||
if (avail < 2)
|
||||
if ((!terminate) && (avail < 2))
|
||||
goto done;
|
||||
cur = ctxt->input->cur[0];
|
||||
next = ctxt->input->cur[1];
|
||||
if (cur == 0) {
|
||||
if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
|
||||
ctxt->sax->setDocumentLocator(ctxt->userData,
|
||||
&xmlDefaultSAXLocator);
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
|
||||
xmlHaltParser(ctxt);
|
||||
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
||||
ctxt->sax->endDocument(ctxt->userData);
|
||||
goto done;
|
||||
}
|
||||
if ((cur == '<') && (next == '?')) {
|
||||
/* PI or XML decl */
|
||||
if (avail < 5) goto done;
|
||||
if ((!terminate) &&
|
||||
(!xmlParseLookupString(ctxt, 2, "?>", 2)))
|
||||
goto done;
|
||||
@ -11034,11 +11023,12 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
int line = ctxt->input->line;
|
||||
int nsNr = ctxt->nsNr;
|
||||
|
||||
if (avail < 2)
|
||||
if ((!terminate) && (avail < 2))
|
||||
goto done;
|
||||
cur = ctxt->input->cur[0];
|
||||
if (cur != '<') {
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_DOCUMENT_EMPTY,
|
||||
"Start tag expected, '<' not found");
|
||||
xmlHaltParser(ctxt);
|
||||
if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
|
||||
ctxt->sax->endDocument(ctxt->userData);
|
||||
@ -11213,8 +11203,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
|
||||
break;
|
||||
}
|
||||
case XML_PARSER_END_TAG:
|
||||
if (avail < 2)
|
||||
goto done;
|
||||
if ((!terminate) && (!xmlParseLookupChar(ctxt, '>')))
|
||||
goto done;
|
||||
if (ctxt->sax2) {
|
||||
@ -11532,9 +11520,20 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
|
||||
/*
|
||||
* Check for termination
|
||||
*/
|
||||
if (ctxt->input->cur < ctxt->input->end) {
|
||||
if (ctxt->errNo == XML_ERR_OK)
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
|
||||
if ((ctxt->instate != XML_PARSER_EOF) &&
|
||||
(ctxt->instate != XML_PARSER_EPILOG)) {
|
||||
if (ctxt->nameNr > 0) {
|
||||
const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||
int line = ctxt->pushTab[ctxt->nameNr - 1].line;
|
||||
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
|
||||
"Premature end of data in tag %s line %d\n",
|
||||
name, line, NULL);
|
||||
} else if (ctxt->instate == XML_PARSER_START) {
|
||||
xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
|
||||
} else {
|
||||
xmlFatalErrMsg(ctxt, XML_ERR_DOCUMENT_EMPTY,
|
||||
"Start tag expected, '<' not found\n");
|
||||
}
|
||||
} else if ((ctxt->input->buf != NULL) &&
|
||||
(ctxt->input->buf->encoder != NULL) &&
|
||||
(!xmlBufIsEmpty(ctxt->input->buf->raw))) {
|
||||
|
3
result/errors/empty.xml.ent
Normal file
3
result/errors/empty.xml.ent
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/empty.xml:1: parser error : Document is empty
|
||||
|
||||
^
|
3
result/errors/empty.xml.err
Normal file
3
result/errors/empty.xml.err
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/empty.xml:1: parser error : Document is empty
|
||||
|
||||
^
|
4
result/errors/empty.xml.str
Normal file
4
result/errors/empty.xml.str
Normal file
@ -0,0 +1,4 @@
|
||||
./test/errors/empty.xml:1: parser error : Document is empty
|
||||
|
||||
^
|
||||
./test/errors/empty.xml : failed to parse
|
3
result/errors/extra-content.xml.ent
Normal file
3
result/errors/extra-content.xml.ent
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/extra-content.xml:1: parser error : Extra content at the end of the document
|
||||
<d/>x
|
||||
^
|
3
result/errors/extra-content.xml.err
Normal file
3
result/errors/extra-content.xml.err
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/extra-content.xml:1: parser error : Extra content at the end of the document
|
||||
<d/>x
|
||||
^
|
4
result/errors/extra-content.xml.str
Normal file
4
result/errors/extra-content.xml.str
Normal file
@ -0,0 +1,4 @@
|
||||
./test/errors/extra-content.xml:1: parser error : Extra content at the end of the document
|
||||
<d/>x
|
||||
^
|
||||
./test/errors/extra-content.xml : failed to parse
|
3
result/errors/invalid-start-tag-1.xml.ent
Normal file
3
result/errors/invalid-start-tag-1.xml.ent
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/invalid-start-tag-1.xml:1: parser error : Start tag expected, '<' not found
|
||||
x
|
||||
^
|
3
result/errors/invalid-start-tag-1.xml.err
Normal file
3
result/errors/invalid-start-tag-1.xml.err
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/invalid-start-tag-1.xml:1: parser error : Start tag expected, '<' not found
|
||||
x
|
||||
^
|
4
result/errors/invalid-start-tag-1.xml.str
Normal file
4
result/errors/invalid-start-tag-1.xml.str
Normal file
@ -0,0 +1,4 @@
|
||||
./test/errors/invalid-start-tag-1.xml:1: parser error : Start tag expected, '<' not found
|
||||
x
|
||||
^
|
||||
./test/errors/invalid-start-tag-1.xml : failed to parse
|
3
result/errors/invalid-start-tag-2.xml.ent
Normal file
3
result/errors/invalid-start-tag-2.xml.ent
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/invalid-start-tag-2.xml:1: parser error : StartTag: invalid element name
|
||||
<
|
||||
^
|
3
result/errors/invalid-start-tag-2.xml.err
Normal file
3
result/errors/invalid-start-tag-2.xml.err
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/invalid-start-tag-2.xml:1: parser error : StartTag: invalid element name
|
||||
<
|
||||
^
|
4
result/errors/invalid-start-tag-2.xml.str
Normal file
4
result/errors/invalid-start-tag-2.xml.str
Normal file
@ -0,0 +1,4 @@
|
||||
./test/errors/invalid-start-tag-2.xml:1: parser error : StartTag: invalid element name
|
||||
<
|
||||
^
|
||||
./test/errors/invalid-start-tag-2.xml : failed to parse
|
3
result/errors/unclosed-element.xml.ent
Normal file
3
result/errors/unclosed-element.xml.ent
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/unclosed-element.xml:2: parser error : Premature end of data in tag d line 1
|
||||
|
||||
^
|
3
result/errors/unclosed-element.xml.err
Normal file
3
result/errors/unclosed-element.xml.err
Normal file
@ -0,0 +1,3 @@
|
||||
./test/errors/unclosed-element.xml:2: parser error : Premature end of data in tag d line 1
|
||||
|
||||
^
|
4
result/errors/unclosed-element.xml.str
Normal file
4
result/errors/unclosed-element.xml.str
Normal file
@ -0,0 +1,4 @@
|
||||
./test/errors/unclosed-element.xml:2: parser error : Premature end of data in tag d line 1
|
||||
|
||||
^
|
||||
./test/errors/unclosed-element.xml : failed to parse
|
0
test/errors/empty.xml
Normal file
0
test/errors/empty.xml
Normal file
1
test/errors/extra-content.xml
Normal file
1
test/errors/extra-content.xml
Normal file
@ -0,0 +1 @@
|
||||
<d/>x
|
1
test/errors/invalid-start-tag-1.xml
Normal file
1
test/errors/invalid-start-tag-1.xml
Normal file
@ -0,0 +1 @@
|
||||
x
|
1
test/errors/invalid-start-tag-2.xml
Normal file
1
test/errors/invalid-start-tag-2.xml
Normal file
@ -0,0 +1 @@
|
||||
<
|
1
test/errors/unclosed-element.xml
Normal file
1
test/errors/unclosed-element.xml
Normal file
@ -0,0 +1 @@
|
||||
<d>
|
Loading…
Reference in New Issue
Block a user