diff --git a/CHANGELOG.md b/CHANGELOG.md index af1ad0fcb8..4406c493fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Changed - `AbstractBlock::finalize()` now reqires a second parameter, `$endLineNumber` + - `RegexHelper::REGEX_ENTITY` no longer includes the starting `/` or the ending `/i` (#194) ### Fixed - Fixed incorrect `endLine` positions (#187) - Fixed `DocParser::preProcessInput` dropping up to 2 ending newlines instead of just one + - Fixed `EntityParser` not checking for ampersands at the start of the current position (#192, #194) ### Removed - Removed protected function Context::addChild() diff --git a/src/Inline/Parser/EntityParser.php b/src/Inline/Parser/EntityParser.php index 48d72942fc..53ca4c17b4 100644 --- a/src/Inline/Parser/EntityParser.php +++ b/src/Inline/Parser/EntityParser.php @@ -36,7 +36,7 @@ public function getCharacters() */ public function parse(InlineParserContext $inlineContext) { - if ($m = $inlineContext->getCursor()->match(RegexHelper::REGEX_ENTITY)) { + if ($m = $inlineContext->getCursor()->match('/^' . RegexHelper::REGEX_ENTITY . '/i')) { $inlineContext->getContainer()->appendChild(new Text(Html5Entities::decodeEntity($m))); return true; diff --git a/src/Util/RegexHelper.php b/src/Util/RegexHelper.php index abc81e3eef..a8e160964b 100644 --- a/src/Util/RegexHelper.php +++ b/src/Util/RegexHelper.php @@ -52,7 +52,7 @@ class RegexHelper const LINK_TITLE = 26; const REGEX_ESCAPABLE = '[!"#$%&\'()*+,.\/:;<=>?@[\\\\\]^_`{|}~-]'; - const REGEX_ENTITY = '/&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});/i'; + const REGEX_ENTITY = '&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});'; const REGEX_PUNCTUATION = '/^[\x{2000}-\x{206F}\x{2E00}-\x{2E7F}\\\\\'!"#\$%&\(\)\*\+,\-\.\\/:;<=>\?@\[\]\^_`\{\|\}~]/u'; protected $regex = []; @@ -242,7 +242,7 @@ public static function unescape($string) $allEscapedChar = '/\\\\(' . self::REGEX_ESCAPABLE . ')/'; $escaped = preg_replace($allEscapedChar, '$1', $string); - $replaced = preg_replace_callback(self::REGEX_ENTITY, function ($e) { + $replaced = preg_replace_callback('/' . self::REGEX_ENTITY . '/i', function ($e) { return Html5Entities::decodeEntity($e[0]); }, $escaped); diff --git a/tests/functional/data/entities.html b/tests/functional/data/entities.html new file mode 100644 index 0000000000..974539d76b --- /dev/null +++ b/tests/functional/data/entities.html @@ -0,0 +1 @@ +

& before ©

diff --git a/tests/functional/data/entities.md b/tests/functional/data/entities.md new file mode 100644 index 0000000000..6d7f869037 --- /dev/null +++ b/tests/functional/data/entities.md @@ -0,0 +1 @@ +& before ©