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

Sanity checks before starting regex engine

This commit is contained in:
Aidan Woods 2018-04-09 02:32:23 +01:00
parent 450a74fedf
commit 726d4ef44a
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -829,8 +829,9 @@ class Parsedown
protected function blockReference($Line)
{
if (preg_match('/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches))
{
if (strpos($Line['text'], ']') !== false
and preg_match('/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches)
) {
$id = strtolower($matches[1]);
$Data = array(
@ -1448,8 +1449,9 @@ class Parsedown
protected function inlineSpecialCharacter($Excerpt)
{
if (preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches))
{
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]),
@ -1489,8 +1491,9 @@ class Parsedown
return;
}
if (preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
{
if (strpos($Excerpt['context'], 'http') !== false
and preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)
) {
$url = $matches[0][0];
$Inline = array(