misak1 / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

Child nodes of nested nodes not correctly removed #144

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Create a HTML document with a nested menu
(<ul><li><ul><li></li></ul></li></ul>).
2. pq('li')->html('test');

What is the expected output? What do you see instead?

Not sure if I'm supposed to get <ul><li>test</li></ul> or
<ul><li>test<ul><li>test</li></ul></li></ul>. Anyway, you get neither,
instead you get a WSOD (white screen of death).

What version of the product are you using? On what operating system?

phpQuery 0.9.5.386 on Windows 7 64-bit.

Please provide any additional information below.

If the children of said node get removed recursively before modifying the
node contents, the problem goes away. I'm using the following function:

function remove_children(&$node) {
  while ($node->firstChild) {
    while ($node->firstChild->firstChild) {
      google_translate_node_remove_children($node->firstChild);
    }
    $node->removeChild($node->firstChild);
  }
}

Before migrating my app to phpQuery, I was using XPath and experienced
exactly the same problem (got a "Call to a member function on a non-object"
error instead of a WSOD). The problem was fixed in the same way (before I
had only removed the 1st level of children).

Original issue reported on code.google.com by stephane...@gmail.com on 12 Feb 2010 at 1:47