com php-src: Fix #70001: Assigning to DOMNode::textContent does additional entity encoding: ext/dom/node.c ext/dom/tests/bug70001.phpt
| From: | Christoph Michael Becker | Date: | Fri, 04 Sep 2015 23:17:50 +0000 |
| Subject: | com php-src: Fix #70001: Assigning to DOMNode::textContent does additional entity encoding: ext/dom/node.c ext/dom/tests/bug70001.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88917@lists.php.net to get a copy of this message | ||
Commit: b2954c64ab67bca980070c63f43cb7afb7ed6d16
Author: Christoph M. Becker <cmb@php.net> Tue, 7 Jul 2015 14:55:00 +0200
Parents: b59ea797f53f560ae79c55c1ca4956b5e77203d2
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b2954c64ab67bca980070c63f43cb7afb7ed6d16
Log:
Fix #70001: Assigning to DOMNode::textContent does additional entity encoding
Assigning to DOMNode::textContent encodes entities, what does not match the
behavior of DOMText::__construct() and DOMDocument::createTextNode. This patch
changes the behavior of DOMNode::textContent in this regard.
Bugs:
https://bugs.php.net/70001
Changed paths:
M ext/dom/node.c
A ext/dom/tests/bug70001.phpt
Diff:
diff --git a/ext/dom/node.c b/ext/dom/node.c
index 887d6d8..5b955c0 100644
--- a/ext/dom/node.c
+++ b/ext/dom/node.c
@@ -930,7 +930,6 @@ int dom_node_text_content_write(dom_object *obj, zval *newval TSRMLS_DC)
{
xmlNode *nodep = dom_object_get_node(obj);
zval value_copy;
- xmlChar *enc_str;
if (nodep == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
@@ -938,9 +937,9 @@ int dom_node_text_content_write(dom_object *obj, zval *newval TSRMLS_DC)
}
convert_to_string_copy(newval, value_copy);
- enc_str = xmlEncodeEntitiesReentrant(nodep->doc, Z_STRVAL_P(newval));
- xmlNodeSetContent(nodep, enc_str);
- xmlFree(enc_str);
+ /* we have to use xmlNodeAddContent() to get the same behavior as with xmlNewText() */
+ xmlNodeSetContent(nodep, (xmlChar *) "");
+ xmlNodeAddContent(nodep, Z_STRVAL_P(newval));
if (newval == &value_copy) {
zval_dtor(newval);
}
diff --git a/ext/dom/tests/bug70001.phpt b/ext/dom/tests/bug70001.phpt
new file mode 100644
index 0000000..7a8c291
--- /dev/null
+++ b/ext/dom/tests/bug70001.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #70001 (Assigning to DOMNode::textContent does additional entity encoding)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$element = new DOMText('<p>foo & bar</p>');
+var_dump($element->textContent);
+$element = (new DOMDocument())->createTextNode('<p>foo & bar</p>');
+var_dump($element->textContent);
+$element->textContent = ('<p>foo & bar</p>');
+var_dump($element->textContent);
+?>
+--EXPECT--
+string(16) "<p>foo & bar</p>"
+string(16) "<p>foo & bar</p>"
+string(16) "<p>foo & bar</p>"