mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-10-26 20:25:14 +03:00
Fix handling of unexpected EOF in xmlParseContent
Readd the XML_ERR_TAG_NOT_FINISHED error on unexpected EOF which was
removed in commit 62150ed2
.
This commit also introduced a regression for direct users of
xmlParseContent. Unclosed tags weren't checked.
This commit is contained in:
parent
3e80560d4b
commit
de5b624f10
48
parser.c
48
parser.c
@ -9837,16 +9837,15 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlParseContent:
|
||||
* xmlParseContentInternal:
|
||||
* @ctxt: an XML parser context
|
||||
*
|
||||
* Parse a content:
|
||||
*
|
||||
* [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*
|
||||
* Parse a content sequence. Stops at EOF or '</'. Leaves checking of
|
||||
* unexpected EOF to the caller.
|
||||
*/
|
||||
|
||||
void
|
||||
xmlParseContent(xmlParserCtxtPtr ctxt) {
|
||||
static void
|
||||
xmlParseContentInternal(xmlParserCtxtPtr ctxt) {
|
||||
int nameNr = ctxt->nameNr;
|
||||
|
||||
GROW;
|
||||
@ -9921,6 +9920,30 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlParseContent:
|
||||
* @ctxt: an XML parser context
|
||||
*
|
||||
* Parse a content sequence. Stops at EOF or '</'.
|
||||
*
|
||||
* [43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*
|
||||
*/
|
||||
|
||||
void
|
||||
xmlParseContent(xmlParserCtxtPtr ctxt) {
|
||||
int nameNr = ctxt->nameNr;
|
||||
|
||||
xmlParseContentInternal(ctxt);
|
||||
|
||||
if ((ctxt->instate != XML_PARSER_EOF) && (ctxt->nameNr > nameNr)) {
|
||||
const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||
int line = (ptrdiff_t) ctxt->pushTab[ctxt->nameNr * 4 - 2];
|
||||
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
|
||||
"Premature end of data in tag %s line %d\n",
|
||||
name, line, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlParseElement:
|
||||
* @ctxt: an XML parser context
|
||||
@ -9939,9 +9962,20 @@ void
|
||||
xmlParseElement(xmlParserCtxtPtr ctxt) {
|
||||
if (xmlParseElementStart(ctxt) != 0)
|
||||
return;
|
||||
xmlParseContent(ctxt);
|
||||
|
||||
xmlParseContentInternal(ctxt);
|
||||
if (ctxt->instate == XML_PARSER_EOF)
|
||||
return;
|
||||
|
||||
if (CUR == 0) {
|
||||
const xmlChar *name = ctxt->nameTab[ctxt->nameNr - 1];
|
||||
int line = (ptrdiff_t) ctxt->pushTab[ctxt->nameNr * 4 - 2];
|
||||
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
|
||||
"Premature end of data in tag %s line %d\n",
|
||||
name, line, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
xmlParseElementEnd(ctxt);
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ class TestCase(unittest.TestCase):
|
||||
(s,len(s),"dummy.xml",None,0),
|
||||
libxml2.treeError,
|
||||
domain=libxml2.XML_FROM_PARSER,
|
||||
code=libxml2.XML_ERR_LTSLASH_REQUIRED,
|
||||
message='EndTag: \'</\' not found\n',
|
||||
code=libxml2.XML_ERR_TAG_NOT_FINISHED,
|
||||
message='Premature end of data in tag x line 1\n',
|
||||
level=libxml2.XML_ERR_FATAL,
|
||||
file='dummy.xml',
|
||||
line=3)
|
||||
|
@ -2,6 +2,6 @@
|
||||
Bytes: 0xEE 0x5D 0x5D 0x3E
|
||||
<d><![CDATA[0000000000000î]]>
|
||||
^
|
||||
./test/errors/754947.xml:1: parser error : EndTag: '</' not found
|
||||
./test/errors/754947.xml:1: parser error : Premature end of data in tag d line 1
|
||||
<d><![CDATA[0000000000000î]]>
|
||||
^
|
||||
|
@ -2,6 +2,6 @@
|
||||
Bytes: 0xEE 0x5D 0x5D 0x3E
|
||||
<d><![CDATA[0000000000000î]]>
|
||||
^
|
||||
./test/errors/754947.xml:1: parser error : EndTag: '</' not found
|
||||
./test/errors/754947.xml:1: parser error : Premature end of data in tag d line 1
|
||||
<d><![CDATA[0000000000000î]]>
|
||||
^
|
||||
|
Loading…
Reference in New Issue
Block a user