From 9ec8f7a78031e8605e2f0ce0716d8a824b57d2ec Mon Sep 17 00:00:00 2001 From: tipiak75 Date: Mon, 12 Oct 2020 14:23:57 +0200 Subject: [PATCH] Candidate fix for issue #255 : loosen up inline tag splitting regexp --- src/DocBlock/DescriptionFactory.php | 2 +- .../unit/DocBlock/DescriptionFactoryTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index c27d2a01..fdcde26b 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -117,7 +117,7 @@ private function lex(string $contents) : array \{ ) # Match content after the nested inline tag. - [^{}]* + [^{]* )* # If there are more inline tags, match them as well. We use "*" since there may not be any # nested inline tags. ) diff --git a/tests/unit/DocBlock/DescriptionFactoryTest.php b/tests/unit/DocBlock/DescriptionFactoryTest.php index 04280fdb..bcd0b033 100644 --- a/tests/unit/DocBlock/DescriptionFactoryTest.php +++ b/tests/unit/DocBlock/DescriptionFactoryTest.php @@ -220,6 +220,36 @@ public function testDescriptionWithBrokenInlineTags() : void $this->assertSame($contents, $description->render()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::__construct + * @covers ::create + */ + public function testDescriptionCanParseStringWithInlineTagAndBraces() : void + { + $contents = 'This description has a {@link http://phpdoc.org/ This contains {braces} }'; + $context = new Context(''); + $tagFactory = m::mock(TagFactory::class); + $tagFactory->shouldReceive('create') + ->twice() + ->andReturnValues( + [ + new LinkTag('http://phpdoc.org/', new Description('This contains {braces}')), + ] + ); + + $factory = new DescriptionFactory($tagFactory); + $description = $factory->create($contents, $context); + + $this->assertSame($contents, $description->render()); + $this->assertSame('This description has a %1$s', $description->getBodyTemplate()); + } + /** * Provides a series of example strings that the parser should correctly interpret and return. *