Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ace20a

Browse filesBrowse files
committed
[Console] Escape % in command name & description from getDefault*()
1 parent 924670d commit 2ace20a
Copy full SHA for 2ace20a

File tree

2 files changed

+30
-1
lines changed
Filter options

2 files changed

+30
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function process(ContainerBuilder $container)
5555
if (!$r->isSubclassOf(Command::class)) {
5656
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
5757
}
58-
$commandName = $class::getDefaultName();
58+
$commandName = $class::getDefaultName() !== null ? str_replace('%', '%%', $class::getDefaultName()) : null;
5959
}
6060

6161
if (null === $commandName) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ public function visibilityProvider()
118118
];
119119
}
120120

121+
public function testEscapesDefaultFromPhp()
122+
{
123+
$container = new ContainerBuilder();
124+
$container
125+
->register('to-escape', EscapedDefaultsFromPhpCommand::class)
126+
->addTag('console.command')
127+
;
128+
129+
$pass = new AddConsoleCommandPass();
130+
$pass->process($container);
131+
132+
$commandLoader = $container->getDefinition('console.command_loader');
133+
$commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));
134+
135+
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
136+
$this->assertSame(['%%cmd%%' => 'to-escape'], $commandLoader->getArgument(1));
137+
$this->assertEquals([['to-escape' => new ServiceClosureArgument(new TypedReference('to-escape', EscapedDefaultsFromPhpCommand::class))]], $commandLocator->getArguments());
138+
$this->assertSame([], $container->getParameter('console.command.ids'));
139+
140+
$command = $container->get('console.command_loader')->get('%%cmd%%');
141+
142+
$this->assertSame('%cmd%', $command->getName());
143+
}
144+
121145
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
122146
{
123147
$this->expectException(\InvalidArgumentException::class);
@@ -250,3 +274,8 @@ class NamedCommand extends Command
250274
{
251275
protected static $defaultName = 'default';
252276
}
277+
278+
class EscapedDefaultsFromPhpCommand extends Command
279+
{
280+
protected static $defaultName = '%cmd%';
281+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.