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

Added a workaround for a PHP bug caused by regex backtracking

fixes #443 by checking whether the required markers are avaialble in the
text before applying the regex on it.
This commit is contained in:
Carsten Brandt 2016-10-31 15:18:08 +01:00
parent b70633df79
commit e1b30621a9
5 changed files with 5102 additions and 4 deletions

View File

@ -1120,11 +1120,11 @@ class Parsedown
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
if ($Excerpt['text'][1] === $marker and strpos($Excerpt['text'], $marker . $marker, 2) !== false and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
{
$emphasis = 'strong';
}
elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
elseif (strpos($Excerpt['text'], $marker, 1) !== false and preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
{
$emphasis = 'em';
}

View File

@ -1,4 +1,4 @@
<p>example*
<p>Without additional checks, this file causes a segfault in PHP &lt; 7.0, which is caused by Regex Backtrack*
example
example
example

View File

@ -1,4 +1,4 @@
example*
Without additional checks, this file causes a segfault in PHP < 7.0, which is caused by Regex Backtrack*
example
example
example

2549
test/data/dos2.html Normal file

File diff suppressed because it is too large Load Diff

2549
test/data/dos2.md Normal file

File diff suppressed because it is too large Load Diff