Bug #78299 [Opn->Sus]: Custom entities in attributes are lost while importing
Edit report at https://bugs.php.net/bug.php?id=78299&edit=1
ID: 78299
Updated by: cmb@php.net
Reported by: fabian at leo dot org
Summary: Custom entities in attributes are lost while
importing
-Status: Open
+Status: Suspended
Type: Bug
Package: DOM XML related
Operating System: Ubuntu 18.04
PHP Version: 7.3.7
Block user comment: N
Private report: N
New Comment:
This looks like an issue in libxml2. I've written to their
mailing list[1], and suspend this ticket for the time being.
[1] <https://mail.gnome.org/archives/xml/2021-June/msg00002.html>
Previous Comments:
------------------------------------------------------------------------
[2019-10-02 16:19:10] rauldmiller at gmail dot com
Note that this also hits elements which do not follow xml formalisms, such as https://developer.mozilla.org/en-US/docs/Web/Web_Components
------------------------------------------------------------------------
[2019-07-16 09:02:10] fabian at leo dot org
Description:
------------
When importing a DomNode that contains a custom entity in one of it's attributes, into another
DomDocument, the entity is missing from the output of getAttribute().
Note:
This is working if the custom entity is already present in the original document. e.g if you add a
attribute hack="⟨" into the root element of the original document, the output of
getAttribute on the imported DomNode is as expected "index.php?lang=en"
Test script:
---------------
<?php
// Creating document for import
$xml = <<<'XSL'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY lang "lang=en">]>
<ex:bla href="index.php?⟨" xmlns:ex="http://example.com" version="1.0"/>
XSL;
$source = \DomDocument::loadXml($xml);
// Creating original document
$xml = <<<'XSL'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY lang "lang=en">]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ex="http://example.com"
version="1.0"/>
XSL;
$doc1 = \DomDocument::loadXml($xml);
$doc1->documentElement->appendChild($doc1->importNode($source->documentElement));
//echo $doc1->saveXml(); // xml is displayed correct
echo $doc1->documentElement->firstChild->getAttribute("href"); // getAttribute()
is not working: "index.php?"
Expected result:
----------------
index.php?lang=en
Actual result:
--------------
index.php?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78299&edit=1
Thread (3 messages)