Stop bash arrays ending at the first ) inside a comment

Both the reader and the writer ran to the first closing paren, which is only the
array's own close if nothing inside contains one. HOST1_WATCHDOG_SCAN_IGNORE has
carried "(exit 127 — bad image)" for weeks: writes spliced into the middle of it
and were refused by bash -n with a bare false, and reads returned the entries
above it — the Rsync tab showed no intermediate scripts at all and 10 of 17
daily. Arrays now close on a ) that starts its own line, as confform already did.
This commit is contained in:
Gmer4Lfe
2026-08-14 11:35:18 -04:00
parent a2debe972f
commit cbcfbfaaad
3 changed files with 35 additions and 4 deletions
+6 -2
View File
@@ -836,10 +836,14 @@ function vv_log_tail(string $path, int $lines): string {
return implode("\n", array_slice($all, -$lines));
}
// See VV_CONF_ARRAY_BODY in config.php for why this cannot stop at the first `)`.
function vv_parse_bash_array(string $raw, string $varName): array {
if (!preg_match('/^\s*' . preg_quote($varName, '/') . '\s*=\s*\(([^)]*)\)/ms', $raw, $m)) return [];
if (!preg_match('/^\s*' . preg_quote($varName, '/') . '\s*=\s*\(' . VV_CONF_ARRAY_BODY . '/ms',
$raw, $m)) return [];
// Group 2 exists only when the multi-line branch matched; group 1 is the single-line body.
$body = isset($m[2]) ? $m[2] : ($m[1] ?? '');
$items = [];
foreach (explode("\n", $m[1]) as $line) {
foreach (explode("\n", $body) as $line) {
$line = trim(preg_replace('/#.*$/', '', $line), " \t\"'");
if ($line !== '') $items[] = $line;
}