php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60931 Entity handling for value in setAttribute() and createElement() differ
Submitted: 2012-01-30 04:06 UTC Modified: 2012-01-30 04:13 UTC
From: hrpeters at gmx dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.9 OS: Windows
Private report: No CVE-ID: None
 [2012-01-30 04:06 UTC] hrpeters at gmx dot net
Description:
------------
Two identical input values with entities create different results depending if they're inserted as element or attribute into the DOM tree.

Entity handling differs as seen in the output below.



Test script:
---------------
define ('VAL','index.php?e=t&c=au');
$dd = new DOMDocument('1.0', 'UTF-8');

$root = $dd->createElement('root');
$href= $dd->createElement('href',VAL);
$root->setAttribute('href',VAL);
$root->appendChild($href);

$dd->appendChild($root);
echo $dd->saveXML();

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<root href="index.php?e=t&amp;c=au"><href>index.php?e=t&amp;c=au</href></root>

Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<root href="index.php?e=t&amp;amp;c=au"><href>index.php?e=t&amp;c=au</href></root>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-30 04:13 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is documented behaviour, per the notes at 
http://au2.php.net/domdocument.createElement -- the node value is not escaped if 
you use the non-standard shorthand in the createElement() method.
 [2012-01-30 04:13 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC