Skip to content

Commit ae20798

Browse files
committed
Fix rendering a description when it contains escaped characters and no tags
1 parent 7b21721 commit ae20798

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/DocBlock/Description.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getTags(): array
9494
public function render(?Formatter $formatter = null): string
9595
{
9696
if ($this->tags === []) {
97-
return $this->bodyTemplate;
97+
return vsprintf($this->bodyTemplate, []);
9898
}
9999

100100
if ($formatter === null) {

tests/unit/DocBlock/DescriptionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,31 @@ public function testDescriptionMultipleTagsCanBeCastToString(): void
142142
. 'inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})';
143143
$this->assertSame($expected, (string) $fixture);
144144
}
145+
146+
/**
147+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
148+
*
149+
* @covers ::__construct
150+
* @covers ::render
151+
* @covers ::__toString
152+
*/
153+
public function testDescriptionWithEscapedCharactersAndNoTagsCanBeCastToString(): void
154+
{
155+
//% chars are escaped in \phpDocumentor\Reflection\DocBlock\DescriptionFactory::create
156+
$body = <<<'EOT'
157+
{%% for user in users %%}
158+
{{ user.name }}
159+
{%% endfor %%}';
160+
EOT;
161+
162+
$expected = <<<'EOT'
163+
{% for user in users %}
164+
{{ user.name }}
165+
{% endfor %}';
166+
EOT;
167+
168+
$fixture = new Description($body, []);
169+
170+
$this->assertSame($expected, (string) $fixture);
171+
}
145172
}

0 commit comments

Comments
 (0)