Skip to content

Commit 1927d14

Browse files
committed
Fixing bug when a yaml key with no value ends a file
1 parent f7dd846 commit 1927d14

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private function updateData(array $newData)
217217
}
218218

219219
// 3b) value DID change
220-
$this->log('updating value');
220+
$this->log(sprintf('updating value to {%s}', is_array($newVal) ? '<array>' : $newVal));
221221
$this->changeValueInYaml($newVal);
222222
}
223223

@@ -765,6 +765,12 @@ private function findEndPositionOfValue($value, $offset = null)
765765

766766
$offset = null === $offset ? $this->currentPosition : $offset;
767767

768+
// a value like "foo:" can simply end a file
769+
// this means the value is null
770+
if ($offset === strlen($this->contents)) {
771+
return $offset;
772+
}
773+
768774
preg_match(sprintf('#%s#', $pattern), $this->contents, $matches, PREG_OFFSET_CAPTURE, $offset);
769775
if (empty($matches)) {
770776
throw new YamlManipulationFailedException(sprintf('Cannot find the original value "%s"', $value));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
security:
2+
access_control:
3+
===
4+
$data['security']['access_control'] = 'foo';
5+
===
6+
security:
7+
access_control: foo

0 commit comments

Comments
 (0)