Skip to content

Commit 8b26da7

Browse files
committed
fix: use regex to extract set and record array
1 parent 2a24e43 commit 8b26da7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

apps/web/src/features/upload/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ function isZodArrayDef(def: AnyZodTypeDef): def is z.ZodArrayDef {
7878
// TODO - fix extract set and record array functions to handle whitespace and trailing semicolon (present or included)
7979

8080
function extractSetEntry(entry: string) {
81-
return entry.slice(4, -1); // 'SET('
81+
const result = /SET\(\s*(.*?)\s*\)/.exec(entry);
82+
if (!result?.[1]) {
83+
throw new Error(`Failed to extract set value from entry: '${entry}'`);
84+
}
85+
return result[1];
8286
}
8387

8488
function extractRecordArrayEntry(entry: string) {
85-
if (entry.lastIndexOf(';') === entry.length - 2) {
86-
return entry.slice(13, -2);
89+
const result = /RECORD_ARRAY\(\s*(.*?)[\s;]*\)/.exec(entry);
90+
if (!result?.[1]) {
91+
throw new Error(`Failed to extract record array value from entry: '${entry}'`);
8792
}
88-
return entry.slice(13, -1);
93+
return result[1];
8994
}
9095

9196
export function reformatInstrumentData({

0 commit comments

Comments
 (0)