Skip to content

Commit

Permalink
bug #1476 [ysm] handle linebreak followed by an immediate root-level …
Browse files Browse the repository at this point in the history
…comment
  • Loading branch information
jrushlow authored Mar 28, 2024
1 parent 50c7d96 commit 07614b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,12 @@ private function advanceCurrentPosition(int $newPosition): void
return;
}

if (str_starts_with($advancedContent, "\n#") || str_starts_with($advancedContent, "\r\n#")) {
$this->log('A linebreak followed by a root-level comment, no indent changes');

return;
}

if (str_contains($advancedContent, "\n")) {
$lines = explode("\n", $advancedContent);
if (!empty($lines)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Util/YamlSourceManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testSetData(string $startingSource, array $newData, string $expe
$this->assertSame($expectedSource, $actualContents);
}

private function getYamlDataTests()
private function getYamlDataTests(): \Generator
{
$finder = new Finder();
$finder->in(__DIR__.'/yaml_fixtures')
Expand Down Expand Up @@ -82,14 +82,14 @@ private function getYamlDataTests()
*/
}

public function getYamlDataTestsUnixSlashes()
public function getYamlDataTestsUnixSlashes(): \Generator
{
foreach ($this->getYamlDataTests() as $key => $data) {
yield 'unix_'.$key => $data;
}
}

public function getYamlDataTestsWindowsSlashes()
public function getYamlDataTestsWindowsSlashes(): \Generator
{
foreach ($this->getYamlDataTests() as $key => $data) {
$data['source'] = str_replace("\n", "\r\n", $data['source']);
Expand Down
13 changes: 13 additions & 0 deletions tests/Util/yaml_fixtures/new_line_with_root_level_comment.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
security:
firewalls:
# main:
===
$data['security'] = [
'firewalls' => 'a firewall',
'providers' => 'a provider'
];
===
security:
firewalls: 'a firewall'
providers: 'a provider'
# main:

0 comments on commit 07614b5

Please sign in to comment.