Karaka-Management / phpOMS

PHP Framework
Other
2 stars 0 forks source link

Potential bug in RecursiveDepthFirst function in the Markdown parser #361

Closed spl1nes closed 4 months ago

spl1nes commented 7 months ago

File: phpOMS/Utils/Parser/markdown/Markdown.php

See this function:

protected function elementApplyRecursiveDepthFirst(string|\Closure $closure, array $element) : array
    {
        if (isset($element['elements'])) {
            foreach ($element['elements'] as &$e) {
                $e = $this->elementApplyRecursiveDepthFirst($closure, $e);
            }
        } elseif (isset($element['element'])) {
            // @bug is this loop even correct? See function `elementApplyRecursive()` where we don't loop
            foreach ($element['element'] as &$e) {
                $e = $this->elementApplyRecursiveDepthFirst($closure, $e);
            }
        }

        return \is_string($closure) ? $this->{$closure}($element) : $closure($element);
    }

Compare with this function:

protected function elementApplyRecursive(string|\Closure $closure, array $element) : array
    {
        $element = \is_string($closure) ? $this->{$closure}($element) : $closure($element);

        if (isset($element['elements'])) {
            foreach ($element['elements'] as &$e) {
                $e = $this->elementApplyRecursive($closure, $e);
            }
        } elseif (isset($element['element'])) {
            $element['element'] = $this->elementApplyRecursive($closure, $element['element']);
        }

        return $element;
    }
spl1nes commented 4 months ago

Second function got removed.