From bc3d77c42273fcebf2601b77da4969bdf264dfe8 Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Sat, 22 Oct 2022 16:13:35 +0200 Subject: [PATCH] Fix escaping of all control chars in exportNode --- src/ts/storage/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ts/storage/index.ts b/src/ts/storage/index.ts index f789f67..f808df8 100644 --- a/src/ts/storage/index.ts +++ b/src/ts/storage/index.ts @@ -1624,7 +1624,16 @@ export class Storage extends SimpleEventEmitter { : writeFn; const stringifyValue = (type: number, val: any) => { - const escape = (str: string) => str.replace(/"/g, '\\"').replace(/\n/g, '\\n'); + const escape = (str: string) => str + .replace(/\\/g, '\\\\') // forward slashes + .replace(/"/g, '\\"') // quotes + .replace(/\r/g, '\\r') // carriage return + .replace(/\n/g, '\\n') // line feed + .replace(/\t/g, '\\t') // tabs + .replace(/[\u0000-\u001f]/g, // other control characters + ch => `\\u${ch.charCodeAt(0).toString(16).padStart(4, '0')}` + ); + if (type === VALUE_TYPES.DATETIME) { val = `"${val.toISOString()}"`; if (options.type_safe) {