10000 Merge branch '6.0' into 6.1 · symfony/console@f112d38 · GitHub
[go: up one dir, main page]

Skip to content

Commit f112d38

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [Console] Prevent PHP 8.1 str_replace deprec on null Improve DE translations for Form/Validator [Serializer] Fix ignore attribute in Xml files [Console] Escape % in command name & description from getDefault*() [WebProfilerBundle] Fix dark theme selected line highlight color & reuse css vars [Mime] Check that the path is a file in the DataPart::fromPath [Cache] do not pass null to strlen() [Mailer] Sort transports alphabetically [Security] Fix some phpdoc [Serializer] Get attributeContext after converting name
2 parents c964619 + 97152b3 commit f112d38

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

DependencyInjection/AddConsoleCommandPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function process(ContainerBuilder $container)
5050
if (!$r->isSubclassOf(Command::class)) {
5151
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
5252
}
53-
$aliases = $class::getDefaultName();
53+
$aliases = str_replace('%', '%%', $class::getDefaultName() ?? '');
5454
}
5555

5656
$aliases = explode('|', $aliases ?? '');
@@ -107,7 +107,7 @@ public function process(ContainerBuilder $container)
107107
if (!$r->isSubclassOf(Command::class)) {
108108
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
109109
}
110-
$description = $class::getDefaultDescription();
110+
$description = str_replace('%', '%%', $class::getDefaultDescription());
111111
}
112112

113113
if ($description) {

Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,33 @@ public function testProcessFallsBackToDefaultDescription()
154154
$this->assertSame(1 + $initCounter, DescribedCommand::$initCounter);
155155
}
156156

157+
public function testEscapesDefaultFromPhp()
158+
{
159+
$container = new ContainerBuilder();
160+
$container
161+
->register('to-escape', EscapedDefaultsFromPhpCommand::class)
162+
->addTag('console.command')
163+
;
164+
165+
$pass = new AddConsoleCommandPass();
166+
$pass->process($container);
167+
168+
$commandLoader = $container->getDefinition('console.command_loader');
169+
$commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));
170+
171+
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
172+
$this->assertSame(['%%cmd%%' => 'to-escape', '%%cmdalias%%' => 'to-escape'], $commandLoader->getArgument(1));
173+
$this->assertEquals([['to-escape' => new ServiceClosureArgument(new Reference('.to-escape.lazy'))]], $commandLocator->getArguments());
174+
$this->assertSame([], $container->getParameter('console.command.ids'));
175+
176+
$command = $container->get('console.command_loader')->get('%%cmd%%');
177+
178+
$this->assertInstanceOf(LazyCommand::class, $command);
179+
$this->assertSame('%cmd%', $command->getName());
180+
$this->assertSame(['%cmdalias%'], $command->getAliases());
181+
$this->assertSame('Creates a 80% discount', $command->getDescription());
182+
}
183+
157184
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
158185
{
159186
$this->expectException(\InvalidArgumentException::class);
@@ -287,6 +314,12 @@ class NamedCommand extends Command
287314
{
288315
}
289316

317+
class EscapedDefaultsFromPhpCommand extends Command
318+
{
319+
protected static $defaultName = '%cmd%|%cmdalias%';
320+
protected static $defaultDescription = 'Creates a 80% discount';
321+
}
322+
290323
#[AsCommand(name: '|cmdname|cmdalias', description: 'Just testing')]
291324
class DescribedCommand extends Command
292325
{

0 commit comments

Comments
 (0)
0