mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
parser: Fix regression in xmlParserNodeInfo accounting
Commit 62150ed2 broke begin_pos and begin_line when extra node info was recorded. Fixes #523.
This commit is contained in:
parent
eca1116b81
commit
250faf3c83
20
SAX2.c
20
SAX2.c
@ -1830,13 +1830,6 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
|
||||
xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(%s)\n", name);
|
||||
#endif
|
||||
|
||||
/* Capture end position and add node */
|
||||
if (cur != NULL && ctxt->record_info) {
|
||||
ctxt->nodeInfo->end_pos = ctxt->input->cur - ctxt->input->base;
|
||||
ctxt->nodeInfo->end_line = ctxt->input->line;
|
||||
ctxt->nodeInfo->node = cur;
|
||||
xmlParserAddNodeInfo(ctxt, ctxt->nodeInfo);
|
||||
}
|
||||
ctxt->nodemem = -1;
|
||||
|
||||
#ifdef LIBXML_VALID_ENABLED
|
||||
@ -2479,24 +2472,15 @@ xmlSAX2EndElementNs(void *ctx,
|
||||
const xmlChar * URI ATTRIBUTE_UNUSED)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlParserNodeInfo node_info;
|
||||
xmlNodePtr cur;
|
||||
|
||||
if (ctx == NULL) return;
|
||||
cur = ctxt->node;
|
||||
/* Capture end position and add node */
|
||||
if ((ctxt->record_info) && (cur != NULL)) {
|
||||
node_info.end_pos = ctxt->input->cur - ctxt->input->base;
|
||||
node_info.end_line = ctxt->input->line;
|
||||
node_info.node = cur;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
}
|
||||
ctxt->nodemem = -1;
|
||||
|
||||
#ifdef LIBXML_VALID_ENABLED
|
||||
if (ctxt->validate && ctxt->wellFormed &&
|
||||
ctxt->myDoc && ctxt->myDoc->intSubset)
|
||||
ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, cur);
|
||||
ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
|
||||
ctxt->node);
|
||||
#endif /* LIBXML_VALID_ENABLED */
|
||||
|
||||
/*
|
||||
|
53
parser.c
53
parser.c
@ -9945,7 +9945,7 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
||||
const xmlChar *URI = NULL;
|
||||
xmlParserNodeInfo node_info;
|
||||
int line, tlen = 0;
|
||||
xmlNodePtr ret;
|
||||
xmlNodePtr cur;
|
||||
int nsNr = ctxt->nsNr;
|
||||
|
||||
if (((unsigned int) ctxt->nameNr > xmlParserMaxDepth) &&
|
||||
@ -9987,7 +9987,7 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
||||
return(-1);
|
||||
}
|
||||
nameNsPush(ctxt, name, prefix, URI, line, ctxt->nsNr - nsNr);
|
||||
ret = ctxt->node;
|
||||
cur = ctxt->node;
|
||||
|
||||
#ifdef LIBXML_VALID_ENABLED
|
||||
/*
|
||||
@ -10020,17 +10020,23 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
||||
spacePop(ctxt);
|
||||
if (nsNr != ctxt->nsNr)
|
||||
nsPop(ctxt, ctxt->nsNr - nsNr);
|
||||
if ( ret != NULL && ctxt->record_info ) {
|
||||
node_info.end_pos = ctxt->input->consumed +
|
||||
(CUR_PTR - ctxt->input->base);
|
||||
node_info.end_line = ctxt->input->line;
|
||||
node_info.node = ret;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
if (cur != NULL && ctxt->record_info) {
|
||||
node_info.node = cur;
|
||||
node_info.end_pos = ctxt->input->consumed +
|
||||
(CUR_PTR - ctxt->input->base);
|
||||
node_info.end_line = ctxt->input->line;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
if (RAW == '>') {
|
||||
NEXT1;
|
||||
if (cur != NULL && ctxt->record_info) {
|
||||
node_info.node = cur;
|
||||
node_info.end_pos = 0;
|
||||
node_info.end_line = 0;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
}
|
||||
} else {
|
||||
xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_GT_REQUIRED,
|
||||
"Couldn't find end of Start Tag %s line %d\n",
|
||||
@ -10044,17 +10050,6 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
||||
spacePop(ctxt);
|
||||
if (nsNr != ctxt->nsNr)
|
||||
nsPop(ctxt, ctxt->nsNr - nsNr);
|
||||
|
||||
/*
|
||||
* Capture end position and add node
|
||||
*/
|
||||
if ( ret != NULL && ctxt->record_info ) {
|
||||
node_info.end_pos = ctxt->input->consumed +
|
||||
(CUR_PTR - ctxt->input->base);
|
||||
node_info.end_line = ctxt->input->line;
|
||||
node_info.node = ret;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -10069,8 +10064,7 @@ xmlParseElementStart(xmlParserCtxtPtr ctxt) {
|
||||
*/
|
||||
static void
|
||||
xmlParseElementEnd(xmlParserCtxtPtr ctxt) {
|
||||
xmlParserNodeInfo node_info;
|
||||
xmlNodePtr ret = ctxt->node;
|
||||
xmlNodePtr cur = ctxt->node;
|
||||
|
||||
if (ctxt->nameNr <= 0) {
|
||||
if ((RAW == '<') && (NXT(1) == '/'))
|
||||
@ -10091,14 +10085,17 @@ xmlParseElementEnd(xmlParserCtxtPtr ctxt) {
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
|
||||
/*
|
||||
* Capture end position and add node
|
||||
* Capture end position
|
||||
*/
|
||||
if ( ret != NULL && ctxt->record_info ) {
|
||||
node_info.end_pos = ctxt->input->consumed +
|
||||
(CUR_PTR - ctxt->input->base);
|
||||
node_info.end_line = ctxt->input->line;
|
||||
node_info.node = ret;
|
||||
xmlParserAddNodeInfo(ctxt, &node_info);
|
||||
if (cur != NULL && ctxt->record_info) {
|
||||
xmlParserNodeInfoPtr node_info;
|
||||
|
||||
node_info = (xmlParserNodeInfoPtr) xmlParserFindNodeInfo(ctxt, cur);
|
||||
if (node_info != NULL) {
|
||||
node_info->end_pos = ctxt->input->consumed +
|
||||
(CUR_PTR - ctxt->input->base);
|
||||
node_info->end_line = ctxt->input->line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user