mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-12 09:17:37 +03:00
tree: Handle predefined entities in xmlBufGetEntityRefContent
It's possible to create references to predefined entities using the tree
API. This edge case was exposed by making predefined entities const in
commit 63ce5f9a
.
This commit is contained in:
parent
619e2808b5
commit
b8597f46df
20
testparser.c
20
testparser.c
@ -59,6 +59,25 @@ testUnsupportedEncoding(void) {
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
testNodeGetContent(void) {
|
||||
xmlDocPtr doc;
|
||||
xmlChar *content;
|
||||
int err = 0;
|
||||
|
||||
doc = xmlReadDoc(BAD_CAST "<doc/>", NULL, NULL, 0);
|
||||
xmlAddChild(doc->children, xmlNewReference(doc, BAD_CAST "lt"));
|
||||
content = xmlNodeGetContent((xmlNodePtr) doc);
|
||||
if (strcmp((char *) content, "<") != 0) {
|
||||
fprintf(stderr, "xmlNodeGetContent failed\n");
|
||||
err = 1;
|
||||
}
|
||||
xmlFree(content);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
static int
|
||||
testBalancedChunk(void) {
|
||||
@ -373,6 +392,7 @@ main(void) {
|
||||
|
||||
err |= testStandaloneWithEncoding();
|
||||
err |= testUnsupportedEncoding();
|
||||
err |= testNodeGetContent();
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
err |= testBalancedChunk();
|
||||
#endif
|
||||
|
10
tree.c
10
tree.c
@ -5504,6 +5504,16 @@ xmlBufGetEntityRefContent(xmlBufPtr buf, const xmlNode *ref) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The parser should always expand predefined entities but it's
|
||||
* possible to create references to predefined entities using
|
||||
* the tree API.
|
||||
*/
|
||||
if (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
|
||||
xmlBufCat(buf, ent->content);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->flags & XML_ENT_EXPANDING)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user