Skip to content

Commit

Permalink
Merge pull request #909 from thephpleague/fix-inline-parser-engine-wi…
Browse files Browse the repository at this point in the history
…th-no-parsers

Fix InlineParserEngine error when no inline parsers are set
  • Loading branch information
colinodell authored Jul 29, 2022
2 parents eab6389 + 82fb5e7 commit 84d7448
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi

## [Unreleased][unreleased]

## [2.3.5] - 2022-07-29

### Fixed

- Fixed error using `InlineParserEngine` when no inline parsers are registered in the `Environment` (#908)

## [2.3.4] - 2022-07-17

### Changed
Expand Down Expand Up @@ -488,7 +494,8 @@ No changes were introduced since the previous release.
- Alternative 1: Use `CommonMarkConverter` or `GithubFlavoredMarkdownConverter` if you don't need to customize the environment
- Alternative 2: Instantiate a new `Environment` and add the necessary extensions yourself

[unreleased]: https://github.com/thephpleague/commonmark/compare/2.3.4...main
[unreleased]: https://github.com/thephpleague/commonmark/compare/2.3.5...main
[2.3.5]: https://github.com/thephpleague/commonmark/compare/2.3.4...2.3.5
[2.3.4]: https://github.com/thephpleague/commonmark/compare/2.3.3...2.3.4
[2.3.3]: https://github.com/thephpleague/commonmark/compare/2.3.2...2.3.3
[2.3.2]: https://github.com/thephpleague/commonmark/compare/2.3.2...main
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/InlineParserEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class InlineParserEngine implements InlineParserEngineInterface
* @psalm-var list<array{0: InlineParserInterface, 1: string, 2: bool}>
* @phpstan-var array<int, array{0: InlineParserInterface, 1: string, 2: bool}>
*/
private array $parsers;
private array $parsers = [];

public function __construct(EnvironmentInterface $environment, ReferenceMapInterface $referenceMap)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/Parser/InlineParserEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use League\CommonMark\Environment\Environment;
use League\CommonMark\Node\Block\Paragraph;
use League\CommonMark\Node\Inline\Text;
use League\CommonMark\Parser\Inline\InlineParserMatch;
use League\CommonMark\Parser\InlineParserEngine;
use League\CommonMark\Reference\ReferenceMap;
Expand Down Expand Up @@ -62,4 +63,17 @@ public function testParseWithDifferentPriorityOrder(): void
$this->assertSame(['lazy'], $adjectiveParser->getMatches());
$this->assertSame(['quick', 'jumps'], $fiveLetterParser->getMatches());
}

public function testParseWithNoInlineParsers(): void
{
$environment = new Environment();
$engine = new InlineParserEngine($environment, new ReferenceMap());
$paragraph = new Paragraph();
$engine->parse('The quick brown fox jumps over the lazy dog', $paragraph);

$this->assertCount(1, $paragraph->children());
$child = $paragraph->firstChild();
$this->assertTrue($child instanceof Text);
$this->assertSame('The quick brown fox jumps over the lazy dog', $child->getLiteral());
}
}

0 comments on commit 84d7448

Please sign in to comment.