8000 bug #1476 [ysm] handle linebreak followed by an immediate root-level … · symfony/maker-bundle@07614b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07614b5

Browse files
authored
bug #1476 [ysm] handle linebreak followed by an immediate root-level comment
1 parent 50c7d96 commit 07614b5

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,12 @@ private function advanceCurrentPosition(int $newPosition): void
915915
return;
916916
}
917917

918+
if (str_starts_with($advancedContent, "\n#") || str_starts_with($advancedContent, "\r\n#")) {
919+
$this->log('A linebreak followed by a root-level comment, no indent changes');
920+
921+
return;
922+
}
923+
918924
if (str_contains($advancedContent, "\n")) {
919925
$lines = explode("\n& 8000 quot;, $advancedContent);
920926
if (!empty($lines)) {

tests/Util/YamlSourceManipulatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testSetData(string $startingSource, array $newData, string $expe
4848
$this->assertSame($expectedSource, $actualContents);
4949
}
5050

51-
private function getYamlDataTests()
51+
private function getYamlDataTests(): \Generator
5252
{
5353
$finder = new Finder();
5454
$finder->in(__DIR__.'/yaml_fixtures')
@@ -82,14 +82,14 @@ private function getYamlDataTests()
8282
*/
8383
}
8484

85-
public function getYamlDataTestsUnixSlashes()
85+
public function getYamlDataTestsUnixSlashes(): \Generator
8686
{
8787
foreach ($this->getYamlDataTests() as $key => $data) {
8888
yield 'unix_'.$key => $data;
8989
}
9090
}
9191

92-
public function getYamlDataTestsWindowsSlashes()
92+
public function getYamlDataTestsWindowsSlashes(): \Generator
9393
{
9494
foreach ($this->getYamlDataTests() as $key => $data) {
9595
$data['source'] = str_replace("\n", "\r\n", $data['source']);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
security:
2+
firewalls:
3+
# main:
4+
===
5+
$data['security'] = [
6+
'firewalls' => 'a firewall',
7+
'providers' => 'a provider'
8+
];
9+
===
10+
security:
11+
firewalls: 'a firewall'
12+
providers: 'a provider'
13+
# main:

0 commit comments

Comments
 (0)
0