diff --git a/src/persist/fileAdapter.ts b/src/persist/fileAdapter.ts index 8bf87d5..e6b7f8c 100644 --- a/src/persist/fileAdapter.ts +++ b/src/persist/fileAdapter.ts @@ -71,7 +71,7 @@ export class FileAdapter implements Adapter { gList.forEach((n) => { n.policy.forEach((m) => { result += n.key + ', '; - result += arrayToString(m); + result += arrayToString(m.map((element) => this.escapeCsv(element))); result += '\n'; }); }); @@ -80,6 +80,14 @@ export class FileAdapter implements Adapter { return true; } + private escapeCsv(value: string): string { + // If the value contains a comma, wrap it in double quotes and escape any existing double quotes + if (value.includes(',')) { + return `"${value.replace(/"/g, '""')}"`; + } + return value; + } + private async savePolicyFile(text: string): Promise { (this.fs ? this.fs : mustGetDefaultFileSystem()).writeFileSync(this.filePath, text); }