Skip to content

Commit

Permalink
Fix #70001: Assigning to DOMNode::textContent does additional entity …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
cmb69 committed Sep 4, 2015
1 parent b59ea79 commit b2954c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,17 +930,16 @@ 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);
return FAILURE;
}

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);
}
Expand Down
17 changes: 17 additions & 0 deletions ext/dom/tests/bug70001.phpt
Original file line number Diff line number Diff line change
@@ -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>"

0 comments on commit b2954c6

Please sign in to comment.