1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 03:55:04 +03:00

valid: Restore ID lookup

Revert a change from d025cfbb and don't overwrite ID table entries, so
that the first attribute will be returned if there are duplicate IDs.

This requires two other changes:

- Attributes in entity content are never added to the ID table. This
  seems reasonable.

- Remove the optimization to skip ID lookup when copying and the target
  document has an empty ID table. This also seems more correct since the
  document could have ID declarations nevertheless or we could be
  copying xml:ids into the document for the first time.

Fixes #757.
This commit is contained in:
Nick Wellnhofer 2024-07-03 11:46:06 +02:00
parent f906526175
commit 842a044831
4 changed files with 8 additions and 14 deletions

2
SAX2.c
View File

@ -1171,6 +1171,7 @@ xmlSAX1Attribute(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
} else
#endif /* LIBXML_VALID_ENABLED */
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
(ctxt->input->entity == NULL) &&
/* Don't create IDs containing entity references */
(ret->children != NULL) &&
(ret->children->type == XML_TEXT_NODE) &&
@ -2038,6 +2039,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
} else
#endif /* LIBXML_VALID_ENABLED */
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
(ctxt->input->entity == NULL) &&
/* Don't create IDs containing entity references */
(ret->children != NULL) &&
(ret->children->type == XML_TEXT_NODE) &&

View File

@ -1,6 +1,6 @@
Object is a Node Set :
Set contains 1 nodes:
1 ELEMENT err
1 ELEMENT foo
ATTRIBUTE id
TEXT
content=bar

1
tree.c
View File

@ -4041,7 +4041,6 @@ xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) {
*/
if ((target != NULL) && (cur != NULL) &&
(target->doc != NULL) && (cur->doc != NULL) &&
(cur->doc->ids != NULL) &&
(cur->parent != NULL) &&
(cur->children != NULL)) {
int res = xmlIsID(cur->doc, cur->parent, cur);

17
valid.c
View File

@ -2327,9 +2327,6 @@ xmlAddIDInternal(xmlAttrPtr attr, const xmlChar *value, xmlIDPtr *idPtr) {
if (doc == NULL)
return(0);
if (attr->id != NULL)
xmlRemoveID(doc, attr);
/*
* Create the ID table if needed.
*/
@ -2340,14 +2337,8 @@ xmlAddIDInternal(xmlAttrPtr attr, const xmlChar *value, xmlIDPtr *idPtr) {
return(-1);
} else {
id = xmlHashLookup(table, value);
if (id != NULL) {
if (id->attr != NULL) {
id->attr->id = NULL;
id->attr->atype = 0;
}
ret = 0;
goto done;
}
if (id != NULL)
return(0);
}
id = (xmlIDPtr) xmlMalloc(sizeof(xmlID));
@ -2365,6 +2356,9 @@ xmlAddIDInternal(xmlAttrPtr attr, const xmlChar *value, xmlIDPtr *idPtr) {
return(-1);
}
if (attr->id != NULL)
xmlRemoveID(doc, attr);
if (xmlHashAddEntry(table, value, id) < 0) {
xmlFreeID(id);
return(-1);
@ -2374,7 +2368,6 @@ xmlAddIDInternal(xmlAttrPtr attr, const xmlChar *value, xmlIDPtr *idPtr) {
if (idPtr != NULL)
*idPtr = id;
done:
id->attr = attr;
id->lineno = xmlGetLineNo(attr->parent);
attr->atype = XML_ATTRIBUTE_ID;