Skip to content

Commit 0dd7d93

Browse files
bug #62764 [Console] Escape % in description of console commands (SiebeVE)
This PR was merged into the 7.3 branch. Discussion ---------- [Console] Escape `%` in description of console commands | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | Fix #62763 | License | MIT Commits ------- 91d0e4c bug #62763 [Console] Escape the description passed to the lazy command so the container can be build without wanting to replace the %not-a-param% to parameters
2 parents bb2e6f9 + 91d0e4c commit 0dd7d93

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ public function process(ContainerBuilder $container): void
135135
}
136136

137137
if ($description) {
138-
$definition->addMethodCall('setDescription', [str_replace('%', '%%', $description)]);
138+
$escapedDescription = str_replace('%', '%%', $description);
139+
$definition->addMethodCall('setDescription', [$escapedDescription]);
139140

140141
$container->register('.'.$id.'.lazy', LazyCommand::class)
141-
->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]);
142+
->setArguments([$commandName, $aliases, $escapedDescription, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]);
142143

143144
$lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy');
144145
}

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ public function testProcessInvokableCommand()
327327
self::assertSame('The %command.name% command help content.', $command->getHelp());
328328
}
329329

330+
public function testProcessCommandWithDescriptionWithpercentageSigns()
331+
{
332+
$container = new ContainerBuilder();
333+
$container
334+
->register(
335+
'description_with_percentage_signs_command',
336+
DescriptionWithPercentageSignsCommand::class,
337+
)
338+
->addTag('console.command')
339+
;
340+
$pass = new AddConsoleCommandPass();
341+
$pass->process($container);
342+
343+
$command = $container->get('console.command_loader')->get('description-percentage-signs');
344+
345+
self::assertTrue($container->has('description_with_percentage_signs_command.command'));
346+
self::assertSame('Just testing %percentage-signs%', $command->getDescription());
347+
}
348+
330349
public function testProcessInvokableSignalableCommand()
331350
{
332351
$container = new ContainerBuilder();
@@ -384,6 +403,14 @@ public function __invoke(): void
384403
}
385404
}
386405

406+
#[AsCommand(name: 'description-percentage-signs', description: 'Just testing %percentage-signs%')]
407+
class DescriptionWithPercentageSignsCommand
408+
{
409+
public function __invoke(): void
410+
{
411+
}
412+
}
413+
387414
#[AsCommand(name: 'invokable-signalable', description: 'Just testing', help: 'The %command.name% help content.')]
388415
class InvokableSignalableCommand implements SignalableCommandInterface
389416
{

0 commit comments

Comments
 (0)