mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
fix(dotenv): handle single-quotes in values in stringify()
(#5846)
* refactor(dotenv): add parse function and test * refactor(dotenv): escape single quotes in stringify function * refactor(dotenv): fix stringify function to correctly escape single quotes * refactor(dotenv): fix stringify function to correctly escape single quotes * tweak --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
2c4287178a
commit
8b9a139472
@ -27,7 +27,7 @@ export function stringify(object: Record<string, string>): 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 = `"`;
|
||||
|
@ -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"`,
|
||||
));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user