Skip to content

Commit a240428

Browse files
Merge branch '6.2' into 6.3
* 6.2: Fix test class name trim(): Argument #1 () must be of type string, bool given Check if trace.curlCommand is defined in profiler [Dumper] Trim leading newlines when checking if value begins with a space [FrameworkBundle] Make service edges unique Fix the list of supported shells for completions in a phar Fix the usage of the zsh completion through the fpath discovery
2 parents 575e03a + c161e05 commit a240428

File tree

8 files changed

+80
-16
lines changed

8 files changed

+80
-16
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ private function getContainerEnvVars(ContainerBuilder $container): array
337337
protected function getServiceEdges(ContainerBuilder $builder, string $serviceId): array
338338
{
339339
try {
340-
return array_map(fn (ServiceReferenceGraphEdge $edge) => $edge->getSourceNode()->getId(), $builder->getCompiler()->getServiceReferenceGraph()->getNode($serviceId)->getInEdges());
340+
return array_values(array_unique(array_map(
341+
fn (ServiceReferenceGraphEdge $edge) => $edge->getSourceNode()->getId(),
342+
$builder->getCompiler()->getServiceReferenceGraph()->getNode($serviceId)->getInEdges()
343+
)));
341344
} catch (InvalidArgumentException $exception) {
342345
return [];
343346
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/http_client.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
Profile
128128
</th>
129129
{% endif %}
130-
{% if trace.curlCommand is not null %}
130+
{% if trace.curlCommand is defined and trace.curlCommand %}
131131
<th>
132132
<button class="btn btn-sm hidden" title="Copy as cURL" data-clipboard-text="{{ trace.curlCommand }}">Copy as cURL</button>
133133
</th>
@@ -143,7 +143,7 @@
143143
{% endif %}
144144
<tr>
145145
<th class="font-normal">Response</th>
146-
<td{% if trace.curlCommand %} colspan="2"{% endif %}>
146+
<td{% if trace.curlCommand is defined and trace.curlCommand %} colspan="2"{% endif %}>
147147
{% if trace.http_code >= 500 %}
148148
{% set responseStatus = 'error' %}
149149
{% elseif trace.http_code >= 400 %}

src/Symfony/Component/Console/Command/DumpCompletionCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function configure(): void
4848
$shell = $this->guessShell();
4949
[$rcFile, $completionFile] = match ($shell) {
5050
'fish' => ['~/.config/fish/config.fish', "/etc/fish/completions/$commandName.fish"],
51-
'zsh' => ['~/.zshrc', '$fpath[1]/'.$commandName],
51+
'zsh' => ['~/.zshrc', '$fpath[1]/_'.$commandName],
5252
default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"],
5353
};
5454

@@ -143,6 +143,18 @@ private function tailDebugLog(string $commandName, OutputInterface $output): voi
143143
*/
144144
private function getSupportedShells(): array
145145
{
146-
return $this->supportedShells ??= array_map(fn ($f) => pathinfo($f, \PATHINFO_EXTENSION), glob(__DIR__.'/../Resources/completion.*'));
146+
if (null !== $this->supportedShells) {
147+
return $this->supportedShells;
148+
}
149+
150+
$shells = [];
151+
152+
foreach (new \DirectoryIterator(__DIR__.'/../Resources/') as $file) {
153+
if (str_starts_with($file->getBasename(), 'completion.') && $file->isFile()) {
154+
$shells[] = $file->getExtension();
155+
}
156+
}
157+
158+
return $this->supportedShells = $shells;
147159
}
148160
}

src/Symfony/Component/Console/Resources/completion.zsh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#compdef {{ COMMAND_NAME }}
2+
13
# This file is part of the Symfony package.
24
#
35
# (c) Fabien Potencier <[email protected]>

src/Symfony/Component/Console/Terminal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public static function hasSttyAvailable(): bool
136136
private static function initDimensions(): void
137137
{
138138
if ('\\' === \DIRECTORY_SEPARATOR) {
139-
if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) {
139+
$ansicon = getenv('ANSICON');
140+
if (false !== $ansicon && preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim($ansicon), $matches)) {
140141
// extract [w, H] from "wxh (WxH)"
141142
// or [w, h] from "wxh"
142143
self::$width = (int) $matches[1];

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags
7171
}
7272

7373
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && str_contains($value, "\n") && !str_contains($value, "\r")) {
74-
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
75-
// http://www.yaml.org/spec/1.2/spec.html#id2793979
76-
$blockIndentationIndicator = str_starts_with($value, ' ') ? (string) $this->indentation : '';
74+
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value);
7775

7876
if (isset($value[-2]) && "\n" === $value[-2] && "\n" === $value[-1]) {
7977
$blockChompingIndicator = '+';
@@ -100,9 +98,7 @@ public function dump(mixed $input, int $inline = 0, int $indent = 0, int $flags
10098
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
10199

102100
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
103-
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
104-
// http://www.yaml.org/spec/1.2/spec.html#id2793979
105-
$blockIndentationIndicator = str_starts_with($value->getValue(), ' ') ? (string) $this->indentation : '';
101+
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
106102
$output .= sprintf(' |%s', $blockIndentationIndicator);
107103

108104
foreach (explode("\n", $value->getValue()) as $row) {
@@ -147,9 +143,7 @@ private function dumpTaggedValue(TaggedValue $value, int $inline, int $indent, i
147143
$output = sprintf('%s!%s', $prefix ? $prefix.' ' : '', $value->getTag());
148144

149145
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
150-
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
151-
// http://www.yaml.org/spec/1.2/spec.html#id2793979
152-
$blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : '';
146+
$blockIndentationIndicator = $this->getBlockIndentationIndicator($value->getValue());
153147
$output .= sprintf(' |%s', $blockIndentationIndicator);
154148

155149
foreach (explode("\n", $value->getValue()) as $row) {
@@ -165,4 +159,20 @@ private function dumpTaggedValue(TaggedValue $value, int $inline, int $indent, i
165159

166160
return $output."\n".$this->dump($value->getValue(), $inline - 1, $indent, $flags);
167161
}
162+
163+
private function getBlockIndentationIndicator(string $value): string
164+
{
165+
$lines = explode("\n", $value);
166+
167+
// If the first line (that is neither empty nor contains only spaces)
168+
// starts with a space character, the spec requires a block indentation indicator
169+
// http://www.yaml.org/spec/1.2/spec.html#id2793979
170+
foreach ($lines as $line) {
171+
if ('' !== trim($line, ' ')) {
172+
return (' ' === substr($line, 0, 1)) ? (string) $this->indentation : '';
173+
}
174+
}
175+
176+
return '';
177+
}
168178
}

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,42 @@ public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasLeadingSpace
710710
$this->assertSame($data, $this->parser->parse($yml));
711711
}
712712

713+
public function testDumpMultiLineStringAsScalarBlockWhenFirstLineIsEmptyAndSecondLineHasLeadingSpace()
714+
{
715+
$data = [
716+
'data' => [
717+
'multi_line' => "\n the second line has leading spaces\nThe third line does not.",
718+
],
719+
];
720+
721+
$expected = "data:\n multi_line: |4-\n\n the second line has leading spaces\n The third line does not.";
722+
723+
$yml = $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
724+
$this->assertSame($expected, $yml);
725+
$this->assertSame($data, $this->parser->parse($yml));
726+
}
727+
728+
public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasOnlySpaces()
729+
{
730+
$data = [
731+
'data' => [
732+
'multi_line' => " \nthe second line\nThe third line.",
733+
],
734+
];
735+
736+
$expectedData = [
737+
'data' => [
738+
'multi_line' => "\nthe second line\nThe third line.",
739+
],
740+
];
741+
742+
$expectedYml = "data:\n multi_line: |-\n \n the second line\n The third line.";
743+
744+
$yml = $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
745+
$this->assertSame($expectedYml, $yml);
746+
$this->assertSame($expectedData, $this->parser->parse($yml));
747+
}
748+
713749
public function testCarriageReturnFollowedByNewlineIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
714750
{
715751
$data = ["a\r\nb\nc"];

src/Symfony/Contracts/Service/Test/ServiceLocatorTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Psr\Container\ContainerInterface;
1616
use Symfony\Contracts\Service\ServiceLocatorTrait;
1717

18-
abstract class ServiceLocatorTest extends TestCase
18+
abstract class ServiceLocatorTestCase extends TestCase
1919
{
2020
protected function getServiceLocator(array $factories): ContainerInterface
2121
{

0 commit comments

Comments
 (0)