php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70001 Assigning to DOMNode::textContent does additional entity encoding
Submitted: 2015-07-06 12:35 UTC Modified: 2015-09-04 23:38 UTC
From: 2detaz at protonmail dot ch Assigned: cmb
Status: Closed Package: DOM XML related
PHP Version: 5.6.10 OS: Linux Debian 7.5 Wheezy
Private report: No CVE-ID:
 [2015-07-06 12:35 UTC] 2detaz at protonmail dot ch
Description:
------------
Version : PHP 5.6.10-1~dotdeb+7.3 (cli) (built: Jun 15 2015 07:22:09) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

DomNode::textContent is readonly on the php doc http://php.net/manual/en/class.domnode.php#domnode.props.textcontent. As excepted on php5.4.42, the script returns the good result. But on php5.6, the textContent is not readonly and I don't know why PHP does some HTML entity encoding (that's weird) instead of emitting an error or a warning.


Test script:
---------------
$element = new DOMText("  Summary for Test DOMText & with a nbsp char right here .");
var_dump($element->textContent);
$element->textContent = ltrim("  Summary for Test DOMText & with a nbsp char right here .");
var_dump($element->textContent);

Expected result:
----------------
string(92) "  Summary for Test DOMText & with a nbsp char right here ."
string(92) "  Summary for Test DOMText & with a nbsp char right here ."

Actual result:
--------------
string(92) "  Summary for Test DOMText & with a nbsp char right here ."
string(69) "Summary for Test DOMText & with a nbsp char right here .".

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-06 15:09 UTC] cmb@php.net
Confirmed: <http://3v4l.org/lbeVg>.

From the changelog of PHP 5.6.1[1]:

| Made DOMNode::textContent writeable.

So this has to be documented. I'm not sure whether the entity
escaping is intended.

[1] <http://de2.php.net/ChangeLog-5.php#5.6.1>
 [2015-07-06 21:04 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2015-07-06 21:04 UTC] requinix@php.net
https://github.com/php/php-src/commit/f54451c#diff-fa17cddc8718bbe954a564fc2f88164dL943

Text interface: http://www.w3.org/TR/dom/#interface-text
textContent attribute: http://www.w3.org/TR/dom/#dom-node-textcontent

Using the constructor and setting textContent directly (which is permitted) should definitely behave the same way, and nothing I've seen suggests either involves HTML encoding.
 [2015-07-07 13:18 UTC] cmb@php.net
-Summary: overwrite DOMElement textContent properties with trimming +Summary: Assigning to DOMNode::textContent does additional entity encoding
 [2015-07-07 13:18 UTC] cmb@php.net
The missing info that DOMNode::textContent is writable as of PHP
5.6.1 has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some
time to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our
documentation better.

With regard to the additional entity encoding, I've submitted PR
#1395.
 [2015-09-04 23:36 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b2954c64ab67bca980070c63f43cb7afb7ed6d16
Log: Fix #70001: Assigning to DOMNode::textContent does additional entity encoding
 [2015-09-04 23:36 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-09-04 23:38 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2015-09-04 23:38 UTC] cmb@php.net
The fix for this bug has been committed.

Thank you for the report, and for helping us make PHP better.
 [2015-09-15 12:13 UTC] ab@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b2954c64ab67bca980070c63f43cb7afb7ed6d16
Log: Fix #70001: Assigning to DOMNode::textContent does additional entity encoding
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC