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

Ensure $startPosition is positive

This commit is contained in:
Aidan Woods 2019-02-10 22:35:27 +00:00
parent cef5b16ae0
commit 30613b2430
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 1 additions and 9 deletions

View File

@ -42,20 +42,12 @@ final class HardBreak implements Inline
$context = $Excerpt->context(); $context = $Excerpt->context();
$offset = $Excerpt->offset(); $offset = $Excerpt->offset();
if ($offset < 1) {
return null;
}
if (\substr($context, $offset -1, 1) === '\\') { if (\substr($context, $offset -1, 1) === '\\') {
$contentLen = $offset -1; $contentLen = $offset -1;
return new self($offset - $contentLen, $contentLen); return new self($offset - $contentLen, $contentLen);
} }
if ($offset < 2) {
return null;
}
if (\substr($context, $offset -2, 2) === ' ') { if (\substr($context, $offset -2, 2) === ' ') {
$trimTrailingWhitespace = \rtrim(\substr($context, 0, $offset)); $trimTrailingWhitespace = \rtrim(\substr($context, 0, $offset));
$contentLen = \strlen($trimTrailingWhitespace); $contentLen = \strlen($trimTrailingWhitespace);

View File

@ -209,7 +209,7 @@ final class Parsedown
# makes sure that the inline belongs to "our" marker # makes sure that the inline belongs to "our" marker
if ($startPosition > $Excerpt->offset()) { if ($startPosition > $Excerpt->offset() || $startPosition < 0) {
continue; continue;
} }