Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug in RecursiveDepthFirst function in the Markdown parser #361

Closed
spl1nes opened this issue Feb 2, 2024 · 1 comment
Closed

Comments

@spl1nes
Copy link
Member

spl1nes commented Feb 2, 2024

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
Copy link
Member Author

spl1nes commented May 4, 2024

Second function got removed.

@spl1nes spl1nes closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant