[xml] Custom entities in attributes are lost while importing



Hi all,

I'm forwarding this from <https://bugs.php.net/78299>, because I think
it is a libxml2 issue.  Consider:


doc1:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY lang "lang=en">]>
<root href="index.php?&lang;"/>

doc2:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [<!ENTITY lang "lang=en">]>
<root/>


Both documents are parsed, and the documentElement of doc1 is imported
into doc2 (xmlDocCopyNode), and appended as child of the root element.
When reading the value of the href attribute of the newly inserted
element (xmlNodeListGetString), the entity reference is missing:

index.php?

The following patch solves this issue, but I have no idea whether it is
the proper patch.


 tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tree.c b/tree.c
index c707f59..80de6d8 100644
--- a/tree.c
+++ b/tree.c
@@ -1740,6 +1740,8 @@ xmlNodeListGetString(xmlDocPtr doc, const xmlNode
*list, int inLine)
                     if (buffer != NULL) {
                         ret = xmlStrcat(ret, buffer);
                         xmlFree(buffer);
+                    } else if (ent->content != NULL) {
+                        ret = xmlStrcat(ret, ent->content);
                     }
                 } else {
                     ret = xmlStrcat(ret, node->content);


Christoph


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]