Repository: thephpleague/commonmark (php)

Issue:
Error : Typed property League\CommonMark\Parser\InlineParserEngine::$parsers must not be accessed before initialization
### Version(s) affected

2.3.4 (under php 8.1.8)

### Description

Unexpected error when parsing \```\n```

### How to reproduce

```php
$env = new Environment();
$p = new MarkdownParser($env);
$p->parse('```\n```');
```

### Possible solution

_No response_

### Additional context

_No response_

### Did this project help you today? Did it make you happy in any way?

_No response_

Pull request:
Fix InlineParserEngine error when no inline parsers are set
Closes #908 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a12a3c20..8cef5166 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
@@ -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
diff --git a/src/Parser/InlineParserEngine.php b/src/Parser/InlineParserEngine.php
index e1d292c6..a80255ce 100644
--- a/src/Parser/InlineParserEngine.php
+++ b/src/Parser/InlineParserEngine.php
@@ -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)
     {


Test patch:
diff --git a/tests/unit/Parser/InlineParserEngineTest.php b/tests/unit/Parser/InlineParserEngineTest.php
index e47e9b40..5090b13c 100644
--- a/tests/unit/Parser/InlineParserEngineTest.php
+++ b/tests/unit/Parser/InlineParserEngineTest.php
@@ -15,6 +15,7 @@ namespace League\CommonMark\Tests\Unit\Parser;
 
 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;
@@ -62,4 +63,17 @@ final class InlineParserEngineTest extends TestCase
         $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());
+    }
 }