From b2954c64ab67bca980070c63f43cb7afb7ed6d16 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 7 Jul 2015 14:55:00 +0200 Subject: [PATCH 1/2] 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. --- ext/dom/node.c | 7 +++---- ext/dom/tests/bug70001.phpt | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 ext/dom/tests/bug70001.phpt diff --git a/ext/dom/node.c b/ext/dom/node.c index 887d6d80090..5b955c06f3d 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 00000000000..7a8c291d4b2 --- /dev/null +++ b/ext/dom/tests/bug70001.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #70001 (Assigning to DOMNode::textContent does additional entity encoding) +--SKIPIF-- + +--FILE-- +foo & bar

'); +var_dump($element->textContent); +$element = (new DOMDocument())->createTextNode('

foo & bar

'); +var_dump($element->textContent); +$element->textContent = ('

foo & bar

'); +var_dump($element->textContent); +?> +--EXPECT-- +string(16) "

foo & bar

" +string(16) "

foo & bar

" +string(16) "

foo & bar

" From dc1a8dd7f09af5807aadf3ed5ffc9c443cd9e74c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 5 Sep 2015 01:27:59 +0200 Subject: [PATCH 2/2] updated NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 836f8f805f9..061097afe4e 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed bug #70370 (Bundled libtool.m4 doesn't handle FreeBSD 10 when building extensions). (Adam) +- DOM: + . Fixed bug #70001 (Assigning to DOMNode::textContent does additional entity + encoding). (cmb) + - OpenSSL: . Fixed bug #55259 (openssl extension does not get the DH parameters from DH key resource). (Jakub Zelenka)