erusev / parsedown

Better Markdown Parser in PHP

Home Page:https://parsedown.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Uninitialized string offset: 1

hamedgasemi200 opened this issue · comments

commented

When my text contains: & in the header it returns an error. My Parsedown version is 1.8.0-beta-7

protected function inlineSpecialCharacter($Excerpt)
{

        if ($Excerpt['text'][1] !== ' ' and strpos($Excerpt['text'], ';') !== false
            and preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches)
        ) {
            return array(
                'element' => array('rawHtml' => '&' . $matches[1] . ';'),
                'extent' => strlen($matches[0]),
            );
        }

        return;
}

I solved it by overwriting the function

if (isset($Excerpt['text'][1] ) && $Excerpt['text'][1] !== ' ' and strpos($Excerpt['text'], ';') !== false
            and preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches)
        )
...

But please fix this issue.

I am also getting this same PHP Notice.