From fff8ad66bc30ff6498a936228a0c68a558fcbe8e Mon Sep 17 00:00:00 2001 From: Dave Rogers Date: Thu, 26 Nov 2026 00:05:49 -0800 Subject: [PATCH 1/3] fix: update `csv-parse` to 7.0.2 to clear its security alert (#5113) Co-Authored-By: Claude Opus 5.5 Co-authored-by: cc-claude-tools --- app/utils/tsvParser.ts | 7 +++---- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/utils/tsvParser.ts b/app/utils/tsvParser.ts index 8e56f1ce5..b0fceb49d 100644 --- a/app/utils/tsvParser.ts +++ b/app/utils/tsvParser.ts @@ -11,7 +11,7 @@ import fs from "fs"; type ReturnType = string | number | boolean; /** - * Returns the file contents parsed into a model shaped by FIELD, or as row arrays if FIELD is omitted. + * Returns the file contents parsed into a model shaped by FIELD. * * @param content - to be parsed * @param delimiter - csv delimiter @@ -25,14 +25,13 @@ export const parseContentRows = async function parseContentRows( FIELD: { [key: string]: string }, FIELD_TYPE: { [key: string]: string } ): Promise { - if (!FIELD) return parseCsv(content, { delimiter, relax_quotes: true }); const keyTypes = Object.fromEntries( Object.entries(FIELD_TYPE).map(([header, type]) => [FIELD[header], type]) ); - return parseCsv(content, { + return parseCsv(content, { cast: (datum: string, info: CastingContext) => info.header ? datum : parseDatumValue(datum, keyTypes[info.column]), - columns: (row: string[]) => row.map((header: string) => header), + columns: true, delimiter, relax_quotes: true, }); diff --git a/package-lock.json b/package-lock.json index 3824273a8..7f63df223 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@tanstack/react-virtual": "^3", "@types/fhir": "^0.0.35", "copy-to-clipboard": "3", - "csv-parse": "^5.0.4", + "csv-parse": "^7.0.2", "gray-matter": "^4", "jwt-decode": "^3.1.2", "ky": "^1.10.0", @@ -7103,9 +7103,9 @@ "license": "MIT" }, "node_modules/csv-parse": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-5.6.0.tgz", - "integrity": "sha512-l3nz3euub2QMg5ouu5U09Ew9Wf6/wQ8I++ch1loQ0ljmzhmfZYrH9fflS22i/PQEvsPvxCwxgz5q7UB8K1JO4Q==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-7.0.3.tgz", + "integrity": "sha512-YFd3QM/yo17vH91L1IOZuvl09zM0zEEtdfTcOCKWcMdM++MNaQSyp09slXyFCLaPXvHstQFx/xC8myiFHSMUvw==", "license": "MIT" }, "node_modules/d3": { diff --git a/package.json b/package.json index 4574a8198..6f6ba2198 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@tanstack/react-virtual": "^3", "@types/fhir": "^0.0.35", "copy-to-clipboard": "3", - "csv-parse": "^5.0.4", + "csv-parse": "^7.0.2", "gray-matter": "^4", "jwt-decode": "^3.1.2", "ky": "^1.10.0", From 3b008b469387aae5e2b9b166185e99dd8d4e556e Mon Sep 17 00:00:00 2001 From: Dave Rogers Date: Thu, 26 Nov 2026 00:06:12 -0800 Subject: [PATCH 2/3] test: pin `parseContentRows` output with an inline TSV (#5113) Co-Authored-By: Claude Opus 5.5 Co-authored-by: cc-claude-tools --- __tests__/utils/tsvParser.test.ts | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 __tests__/utils/tsvParser.test.ts diff --git a/__tests__/utils/tsvParser.test.ts b/__tests__/utils/tsvParser.test.ts new file mode 100644 index 000000000..30e00de8c --- /dev/null +++ b/__tests__/utils/tsvParser.test.ts @@ -0,0 +1,75 @@ +/** + * @jest-environment node + */ +import { parseContentRows } from "../../app/utils/tsvParser"; + +const FIELD = { + ACTIVE: "Active", + COUNT: "Count", + NAME: "Name", + SIZE: "Size", +}; + +const FIELD_TYPE = { + ACTIVE: "boolean", + COUNT: "number", + NAME: "string", + SIZE: "string", +}; + +// Tab-delimited, with a stray quote in an unquoted value and an empty "Count" cell. +const TSV = [ + "Name\tCount\tActive\tSize", + 'alpha\t1,234\tTRUE\t 12" ruler ', + "beta\t\tfalse\tplain", +].join("\n"); + +interface Row { + Active: boolean; + Count: number; + Name: string; + Size: string; +} + +/** + * Parses the test TSV the way the catalog and consent code builds do. + * @returns parsed rows. + */ +async function parseRows(): Promise { + return parseContentRows(TSV, "\t", FIELD, FIELD_TYPE); +} + +describe("parseContentRows", () => { + test("uses the header row as each row's keys", async () => { + const rows = await parseRows(); + expect(rows).toHaveLength(2); + for (const row of rows) { + expect(Object.keys(row)).toEqual(["Name", "Count", "Active", "Size"]); + } + }); + + test("casts values by field type", async () => { + const [alpha, beta] = await parseRows(); + expect(alpha.Count).toBe(1234); + expect(alpha.Active).toBe(true); + expect(beta.Active).toBe(false); + expect(alpha.Name).toBe("alpha"); + }); + + test("keeps a stray quote in an unquoted value and trims the string", async () => { + const [alpha] = await parseRows(); + expect(alpha.Size).toBe('12" ruler'); + }); + + test("parses an empty number cell as 0", async () => { + const [, beta] = await parseRows(); + expect(beta.Count).toBe(0); + }); + + test("returns the full rows", async () => { + expect(await parseRows()).toEqual([ + { Active: true, Count: 1234, Name: "alpha", Size: '12" ruler' }, + { Active: false, Count: 0, Name: "beta", Size: "plain" }, + ]); + }); +}); From 06d4fd0a2525d2842183246379e85ccf8322f16f Mon Sep 17 00:00:00 2001 From: Dave Rogers Date: Thu, 26 Nov 2026 00:10:07 -0800 Subject: [PATCH 3/3] docs: describe what `parseContentRows` returns (#5113) Co-Authored-By: Claude Opus 5.5 Co-authored-by: cc-claude-tools --- app/utils/tsvParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/tsvParser.ts b/app/utils/tsvParser.ts index b0fceb49d..fb7e52b96 100644 --- a/app/utils/tsvParser.ts +++ b/app/utils/tsvParser.ts @@ -17,7 +17,7 @@ type ReturnType = string | number | boolean; * @param delimiter - csv delimiter * @param FIELD - fields * @param FIELD_TYPE - field types - * @returns @see ReturnType[] + * @returns one object per row, keyed by header. */ export const parseContentRows = async function parseContentRows( content: Buffer | string,