Skip to content

Commit 15d23ae

Browse files
committed
Fixing a bug where we improperly tracked indentation in 2 different ways
1 parent 0ab615a commit 15d23ae

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,19 @@ private function advanceCurrentPosition(int $newPosition)
783783
return;
784784
}
785785

786+
/*
787+
* A bit of a workaround. At times, this function will be called when the
788+
* position is at the beginning of the line: so, one character *after*
789+
* a line break. In that case, if there are a group of spaces at the
790+
* beginning of this first line, they *should* be used to calculate the new
791+
* indentation. To force this, if we detect this situation, we move one
792+
* character backwards, so that the first line is considered a valid line
793+
* to look for indentation.
794+
*/
795+
if ($this->isCharLineBreak(substr($this->contents, $originalPosition - 1, 1))) {
796+
$originalPosition--;
797+
}
798+
786799
// look for empty lines and track the current indentation
787800
$advancedContent = substr($this->contents, $originalPosition, $newPosition - $originalPosition);
788801
$previousIndentation = $this->indentationForDepths[$this->depth];
@@ -872,7 +885,11 @@ private function guessNextArrayTypeAndAdvance(): string
872885

873886
// get the next char & advance immediately
874887
$nextCharacter = substr($this->contents, $this->currentPosition, 1);
875-
$this->advanceCurrentPosition($this->currentPosition + 1);
888+
// advance, but without advanceCurrentPosition()
889+
// because we are either moving along one line until [ {
890+
// or we are finding a line break and stopping: indentation
891+
// should not be calculated
892+
$this->currentPosition++;
876893

877894
if ($this->isCharLineBreak($nextCharacter)) {
878895
return self::ARRAY_FORMAT_MULTILINE;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
security:
2+
firewalls:
3+
main:
4+
anonymous: true
5+
guard:
6+
authenticators:
7+
- App\Security\Test
8+
===
9+
$data['security']['firewalls']['main']['guard']['authenticators'][] = 'App\Security\Test2';
10+
===
11+
security:
12+
firewalls:
13+
main:
14+
anonymous: true
15+
guard:
16+
authenticators:
17+
- App\Security\Test
18+
- App\Security\Test2

0 commit comments

Comments
 (0)