diff --git a/testparser.c b/testparser.c index 923a0f2b..d19e9ea5 100644 --- a/testparser.c +++ b/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 "", 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 diff --git a/tree.c b/tree.c index b385663e..71408be0 100644 --- a/tree.c +++ b/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;