php.net |  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: -
Votes:1
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: fabian at leo dot org
New email:
PHP Version: OS:

 

 [2019-07-16 09:02 UTC] 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?&lang;" 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 https://developer.mozilla.org/en-US/docs/Web/Web_Components
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 19:01:25 2020 UTC