1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Apply depth first to avoid risk of segfault if closure creates subelements

This commit is contained in:
Aidan Woods 2018-04-06 19:52:25 +01:00
parent e33f1a48c8
commit 4c9ea94d0c
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -1610,8 +1610,6 @@ class Parsedown
protected function elementApplyRecursive($closure, array $Element) protected function elementApplyRecursive($closure, array $Element)
{ {
$Element = call_user_func($closure, $Element);
if (isset($Element['elements'])) if (isset($Element['elements']))
{ {
$Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']); $Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']);
@ -1621,6 +1619,8 @@ class Parsedown
$Element['element'] = $this->elementApplyRecursive($closure, $Element['element']); $Element['element'] = $this->elementApplyRecursive($closure, $Element['element']);
} }
$Element = call_user_func($closure, $Element);
return $Element; return $Element;
} }