Bug #78299 [Com]: Custom entities in attributes are lost while importing

From: Date: Wed, 02 Oct 2019 16:19:10 +0000
Subject: Bug #78299 [Com]: Custom entities in attributes are lost while importing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222993@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78299&edit=1

 ID:                 78299
 Comment by:         rauldmiller at gmail dot com
 Reported by:        fabian at leo dot org
 Summary:            Custom entities in attributes are lost while
                     importing
 Status:             Open
 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:

Note that this also hits elements which do not follow xml formalisms, such as https://developer.mozilla.org/en-US/docs/Web/Web_Components


Previous Comments:
------------------------------------------------------------------------
[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?&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?


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78299&edit=1


Thread (3 messages)

« previous php.bugs (#222993) next »