diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-01 13:26:34 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-01 13:26:34 +0200 |
| commit | 8f5037a4321633dd96f2f320869aac1f96ed4c01 (patch) | |
| tree | 883f87ce1eadf8baaf38ee0ae033cff8f411aa16 /packages/meshbay-hub/src/meshbay_hub/static/csv.js | |
| parent | b1878ab982ab72571915e7fbe2c1b558ea31f838 (diff) | |
| download | meshbay-8f5037a4321633dd96f2f320869aac1f96ed4c01.tar.gz | |
fix(client): the audit export never hands a spreadsheet a formula
A cell starting with = + - @ (or a tab or carriage return) gets a leading
apostrophe; the export carries text members chose (F-29).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/csv.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/csv.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/csv.js b/packages/meshbay-hub/src/meshbay_hub/static/csv.js new file mode 100644 index 0000000..310bdca --- /dev/null +++ b/packages/meshbay-hub/src/meshbay_hub/static/csv.js @@ -0,0 +1,14 @@ +/** + * One CSV cell, quoted when it has to be, and never a formula. + * + * A spreadsheet runs a cell that starts with `=`, `+`, `-` or `@` (or a tab or a + * carriage return in front of one) as a formula. The audit export carries text + * a member chose — a refused blob's kind, a file name — so such a cell is given + * a leading apostrophe, which spreadsheets read as "this is text", and which is + * what other exports do. + */ +export function csvCell(value) { + let s = value == null ? '' : String(value); + if (/^[=+\-@\t\r]/.test(s)) s = `'${s}`; + return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; +} |