Skip to content

Commit aa6c358

Browse files
committed
Fixing bug where a scalar value would become and array, but comment placement was wrong
1 parent 1927d14 commit aa6c358

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,30 @@ private function changeValueInYaml($value)
461461
// empty space between key & value
462462
$newYamlValue = ' '.$newYamlValue;
463463
}
464+
465+
$newPosition = $this->currentPosition + \strlen($newYamlValue);
466+
$isNextContentComment = $this->isPreviousLineComment($newPosition);
467+
if ($isNextContentComment) {
468+
$newPosition++;
469+
}
470+
464471
$newContents = substr($this->contents, 0, $this->currentPosition)
465472
.$newYamlValue
473+
/*
474+
* If the next line is a comment, this means we probably had
475+
* a structure that looks like this:
476+
* access_control:
477+
* # - { path: ^/admin, roles: ROLE_ADMIN }
478+
*
479+
* In this odd case, we need to know that the next line
480+
* is a comment, so we can add an extra line break.
481+
* Otherwise, the result is something like:
482+
* access_control:
483+
* - { path: /foo, roles: ROLE_USER } # - { path: ^/admin, roles: ROLE_ADMIN }
484+
*/
485+
.($isNextContentComment ? "\n" : '')
466486
.substr($this->contents, $endValuePosition);
467487

468-
$newPosition = $this->currentPosition + \strlen($newYamlValue);
469-
470488
$newData = $this->currentData;
471489
$newData = $this->setValueAtCurrentPath($value, $newData);
472490

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
2+
security:
3+
access_control:
4+
===
5+
$data['security']['access_control'] = [];
6+
$data['security']['access_control'][] = ['path' => '^/login$', 'roles' => 'IS_AUTHENTICATED_ANONYMOUSLY'];
7+
===
8+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
9+
security:
10+
access_control:
11+
-
12+
path: ^/login$
13+
roles: IS_AUTHENTICATED_ANONYMOUSLY
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
2+
security:
3+
access_control:
4+
# - { path: ^/admin, roles: ROLE_ADMIN }
5+
# - { path: ^/profile, roles: ROLE_USER }
6+
===
7+
$data['security']['access_control'] = [];
8+
$data['security']['access_control'][] = ['path' => '^/login$', 'roles' => 'IS_AUTHENTICATED_ANONYMOUSLY'];
9+
===
10+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
11+
security:
12+
access_control:
13+
-
14+
path: ^/login$
15+
roles: IS_AUTHENTICATED_ANONYMOUSLY
16+
# - { path: ^/admin, roles: ROLE_ADMIN }
17+
# - { path: ^/profile, roles: ROLE_USER }

0 commit comments

Comments
 (0)