Skip to content

Commit f461d07

Browse files
committed
bug #816 [YSM] fix array key regex (jrushlow)
This PR was merged into the 1.0-dev branch. Discussion ---------- [YSM] fix array key regex This fixes an issue if an existing array has a `:` within the value, `YamlSourceManipulator` could mistake part of the value for the array key when determining position. E.g. ```yaml config: - '80:80' ``` YSM would pick the `0:` within `80:80` as the array key. Commits ------- fc359f1 fix array key regex
2 parents 313b566 + fc359f1 commit f461d07

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ private function getEndOfPreviousKeyPosition($key): int
684684

685685
private function getKeyRegex($key)
686686
{
687-
return sprintf('#%s( )*:#', preg_quote($key));
687+
return sprintf('#\b%s( )*:#', preg_quote($key));
688688
}
689689

690690
private function updateContents(string $newContents, array $newData, int $newPosition)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
caddy:
2+
ports:
3+
- '80:80'
4+
===
5+
$data['caddy']['ports'][] = '443:443';
6+
===
7+
caddy:
8+
ports:
9+
- '80:80'
10+
- '443:443'

0 commit comments

Comments
 (0)