Guarantee a trailing newline when writing a conf so appends cannot join the last line

This commit is contained in:
Gmer4Lfe
2026-08-04 21:20:42 -04:00
parent 1761087283
commit 90eee5674f
+8
View File
@@ -276,6 +276,14 @@ function vv_read_conf_raw(string $filename): string {
function vv_write_conf_raw(string $filename, string $content): bool {
$path = CONF_DIR . '/' . $filename;
$tmp = $path . '.vv.tmp';
// Guarantee the trailing newline. A textarea does not supply one, so saving through the raw
// editor left master.conf ending mid-line — and appending is a real pattern here
// (conf_upgrade, and the array writers below), so the next `>>` would have joined itself
// onto the last setting instead of starting a line. Appended, never stripped: a deliberate
// run of blank lines at the end of a conf is the author's business.
if ($content !== '' && !str_ends_with($content, "\n")) $content .= "\n";
if (file_put_contents($tmp, $content) === false) return false;
return rename($tmp, $path);
}