fix(cli): quote env values with special characters

This commit is contained in:
Dotta
2026-03-13 15:07:49 -05:00
parent aa799bba4c
commit 626a8f1976
3 changed files with 27 additions and 2 deletions

View File

@@ -22,11 +22,18 @@ function parseEnvFile(contents: string) {
}
}
function formatEnvValue(value: string): string {
if (/^[A-Za-z0-9_./:@-]+$/.test(value)) {
return value;
}
return JSON.stringify(value);
}
function renderEnvFile(entries: Record<string, string>) {
const lines = [
"# Paperclip environment variables",
"# Generated by Paperclip CLI commands",
...Object.entries(entries).map(([key, value]) => `${key}=${value}`),
...Object.entries(entries).map(([key, value]) => `${key}=${formatEnvValue(value)}`),
"",
];
return lines.join("\n");