From 4c9ea94d0c1f1bd67fe48622bc71f081df2aea1d Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Fri, 6 Apr 2018 19:52:25 +0100 Subject: [PATCH] Apply depth first to avoid risk of segfault if closure creates subelements --- Parsedown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 186896c..d62c6c8 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -1610,8 +1610,6 @@ class Parsedown protected function elementApplyRecursive($closure, array $Element) { - $Element = call_user_func($closure, $Element); - if (isset($Element['elements'])) { $Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']); @@ -1621,6 +1619,8 @@ class Parsedown $Element['element'] = $this->elementApplyRecursive($closure, $Element['element']); } + $Element = call_user_func($closure, $Element); + return $Element; }