|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78299 Custom entities in attributes are lost while importing
Submitted: 2019-07-16 09:02 UTC Modified: -
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: fabian at leo dot org Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.3.7 OS: Ubuntu 18.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: fabian at leo dot org
New email:
PHP Version: OS:


 [2019-07-16 09:02 UTC] fabian at leo dot org
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().

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:
// 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?&lang;" xmlns:ex="" version="1.0"/>
$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="" xmlns:ex="" version="1.0"/>
$doc1 = \DomDocument::loadXml($xml);

//echo $doc1->saveXml();  // xml is displayed correct
echo $doc1->documentElement->firstChild->getAttribute("href"); // getAttribute() is not working: "index.php?"

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-02 16:19 UTC] rauldmiller at gmail dot com
Note that this also hits elements which do not follow xml formalisms, such as
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 19:01:25 2020 UTC