diff --git a/dotenv/stringify.ts b/dotenv/stringify.ts index 9d33df93c..34a9ef704 100644 --- a/dotenv/stringify.ts +++ b/dotenv/stringify.ts @@ -27,7 +27,7 @@ export function stringify(object: Record): string { `key starts with a '#' indicates a comment and is ignored: '${key}'`, ); continue; - } else if (escapedValue.includes("\n")) { + } else if (escapedValue.includes("\n") || escapedValue.includes("'")) { // escape inner new lines escapedValue = escapedValue.replaceAll("\n", "\\n"); quote = `"`; diff --git a/dotenv/stringify_test.ts b/dotenv/stringify_test.ts index fd6c46d85..a472e5250 100644 --- a/dotenv/stringify_test.ts +++ b/dotenv/stringify_test.ts @@ -78,4 +78,9 @@ Deno.test("stringify()", async (t) => { `NULL=`, ), ); + await t.step("handles single-quote characters", () => + assertEquals( + stringify({ PARSE: "par'se" }), + `PARSE="par'se"`, + )); });