From 726d4ef44a676de2e2af0c3b1861c9429a257196 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Mon, 9 Apr 2018 02:32:23 +0100 Subject: [PATCH] Sanity checks before starting regex engine --- Parsedown.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 6b7ff86..7fa06e3 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -829,8 +829,9 @@ class Parsedown protected function blockReference($Line) { - if (preg_match('/^\[(.+?)\]:[ ]*+?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches)) - { + if (strpos($Line['text'], ']') !== false + and preg_match('/^\[(.+?)\]:[ ]*+?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $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(