1
0
mirror of https://github.com/GNOME/libxml2.git synced 2025-10-14 19:57:32 +08:00

valid: Don't add ids when validating entity content

The id table shouldn't reference ids in entities. The id will be created
when expanding the entity.

Probably regressed with d025cfbb.

Note that we still register ids in entities if entities are not
replaced. This is required to make IDREF checks work.

Fixes #974.
This commit is contained in:
Nick Wellnhofer
2025-08-23 14:59:50 +02:00
parent 56199b5c08
commit d53ba0588e
3 changed files with 28 additions and 1 deletions

22
SAX2.c
View File

@@ -1190,8 +1190,19 @@ xmlSAX1Attribute(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
xmlFree(val);
}
} else {
/*
* When replacing entities, make sure that IDs in
* entities aren't registered. This also shouldn't be
* done when entities aren't replaced, but this would
* require to rework IDREF checks.
*/
if (ctxt->input->entity != NULL)
ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
ctxt->node, ret, value);
ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
}
} else
#endif /* LIBXML_VALID_ENABLED */
@@ -2057,8 +2068,19 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
if (dup == NULL)
xmlSAX2ErrMemory(ctxt);
/*
* When replacing entities, make sure that IDs in
* entities aren't registered. This also shouldn't be
* done when entities aren't replaced, but this would
* require to rework IDREF checks.
*/
if (ctxt->input->entity != NULL)
ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, dup);
ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
}
} else
#endif /* LIBXML_VALID_ENABLED */

View File

@@ -22,6 +22,10 @@
* Set if the validation is enabled.
*/
#define XML_VCTXT_VALIDATE (1u << 2)
/**
* Set when parsing entities.
*/
#define XML_VCTXT_IN_ENTITY (1u << 3)
/*
* TODO: Rename to avoid confusion with xmlParserInputFlags

View File

@@ -3962,7 +3962,8 @@ xmlValidateOneAttribute(xmlValidCtxt *ctxt, xmlDoc *doc,
}
/* Validity Constraint: ID uniqueness */
if (attrDecl->atype == XML_ATTRIBUTE_ID) {
if (attrDecl->atype == XML_ATTRIBUTE_ID &&
(ctxt->flags & XML_VCTXT_IN_ENTITY) == 0) {
if (xmlAddID(ctxt, doc, value, attr) == NULL)
ret = 0;
}