Fix RemexCompatMunger infinite recursion
authorTim Starling <tstarling@wikimedia.org>
Fri, 17 Nov 2017 11:15:59 +0000 (22:15 +1100)
committerTim Starling <tstarling@wikimedia.org>
Fri, 17 Nov 2017 12:27:14 +0000 (23:27 +1100)
commit324e4bca4f540bca6526b7d0fe88f2ef18807872
treea8bb9269a782ff982a254969c6eeca8ca56cd397
parentfa577b65f2eea8ae4eb5294e5a57c9a35bfb0452
Fix RemexCompatMunger infinite recursion

When TreeBuilder requests reparenting of all child nodes of a given
element, we do this by removing the existing child nodes, and then
inserting the proposed new parent under the old parent. However, when a
p-wrap diversion is in place, the insertion of the new parent is
diverted into the p-wrap, and the p-wrap then becomes a child of the new
parent, causing a reference loop, and ultimately infinite recursion in
Serializer.

Instead, divert the entire reparent request to the p-wrap, so that the
new parent is a child of the p-wrap. This makes sense since the new
parent is always a formatting element. The only caller of
reparentChildren(), apart from proxies, is AAA step 17, which reparents
children under the formatting element cloned from the AFE list.

Left in some debug code for next time.

Bug: T178632
Change-Id: Id77d21d99748e94c064ef24c43ee0033de627b8e
includes/tidy/RemexCompatMunger.php
includes/tidy/RemexMungerData.php
tests/phpunit/includes/tidy/RemexDriverTest.php