fix(api): strip every leading formula trigger in CSV export and keep other values whole [T-2576]
What was wrong
On develop (e0acd75), the CSV export guard in api/src/formatters/csv.ts had two problems:
csv.ts:45listed'=', '+', '-', '@', ',', ';', '0'ā¦'9', '0x0d', '/C', '.exe', '\', '/', '.dll', '|'as risky, andcsv.ts:51-52(if (riskyChars.includes(str.charAt(0))) { return str.replace(str.charAt(0), ''); }) removed only one character.csv.ts:60-61runs it on every term and translation forGET /api/v1/projects/:id/exports?format=csv.
So a doubled trigger still left a live formula once the file was opened in a spreadsheet: ==1+1 was exported as =1+1 and +=cmd|' /C calc'!A0 as =cmd|' /C calc'!A0. Any project editor, or an API client with editor rights, can plant such a term or translation. A leading tab or carriage return was never removed, and '0x0d', '/C', '.exe' and '.dll' are multi-character strings that can never match one character.
The same guard also cut the first character off ordinary values: 404.title became 04.title, 5 minutes became minutes and /help became help. Exports lost data, and importing the file again created the wrong terms.
What changed
csv.ts: only the formula triggers=,+,-,@, tab and carriage return count as risky. The guard keeps removing leading characters while the first one is a trigger, so==1+1and\t=1+1both export as1+1. Values that start with a digit,/,\,,,;or|are left unchanged (csv-stringify already quotes a value that holds the,delimiter). The multi-character entries are gone. It still strips, as before, sofixtures/cleaned.csvis unchanged.docs/changelog.md: one line undernext.
Tests (written first, failing before the fix)
Two new tests in api/src/formatters/csv.spec.ts:
should remove every leading formula trigger, not only the first one: terms and translations==1+1,++1+1,+=cmd|' /C calc'!A0,-=cmd|' /C calc'!A0,@-x,-@x, tab +=1+1and CR +=1+1. The output is read back with csv-parse without trimming, and no cell may start with=,+,-,@, tab or CR.should export values that start with a digit, a slash, a backslash, a comma, a semicolon or a pipe unchanged:{ term: '404.title', translation: '5 minutes' },/help,\server\share,, and more,;commentand| separatedcome back unchanged, both from a raw parse and throughcsvParser(the import path).
Results for csv.spec.ts:
- Before the fix: 2 failed, 4 passed (
Received string: "=1+1", and"04.title"," minutes","help"," and more","comment"). - After the fix: 6 of 6 passed. The existing simple export test and the risky-payload test against
fixtures/cleaned.csvstill pass.
Checks run (Windows, Node 24)
yarn check-fmtat the root (prettier --check "**/*.ts", as CircleCI runs it): all files use Prettier code style.yarn --cwd api lint(tslint): clean.tsc --noEmit -p api/tsconfig.json: clean.yarn --cwd api test(jest--maxWorkers=2): 197 of 198 tests passed, 28 of 29 suites. The only failure issrc/formatters/properties.spec.ts"should export properties files", which this PR does not touch. It fails only on Windows: thepropertieslibrary writes\r\nwhenprocess.platform === "win32"(node_modules/properties/lib/stringify.js:9) and the fixture has\n. CircleCI runs on Linux.api/test/export.e2e-spec.ts(SQLite,--runInBand): 11 of 11 passed, including the CSV export with a fallback locale.
Fleet task T-2576; authored by the lead lane while the fleet is paused by its daily cost ceiling.
š¤ Generated with Claude Code
Summary by cubic
Fixes CSV export so a doubled formula trigger no longer reaches spreadsheet software as a live formula, while ordinary values keep their full content.
- Strips every leading
=,+,-,@, tab, or carriage return from terms and translations, not just the first one, so==1+1and+=cmd|' /C calc'!A0export as plain text. - Exports values that start with a digit,
/,\,,,;, or|unchanged; previously their first character was cut off (404.titlebecame04.title). - Quotes values that contain a carriage return so a spreadsheet cannot start a new row there with a live formula.