Skip to content

Commit cff813c

Browse files
committed
chore: trim whitespaces off csv entries, make regex exlude whitespaces in subjectId
1 parent 3a88ad7 commit cff813c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,16 @@ export async function processInstrumentCSV(
484484
//TODO make this type safe without having to cast z.AnyZodObject
485485
instrumentSchemaWithInternal = (instrumentSchemaDef.schema as z.AnyZodObject).extend({
486486
date: z.coerce.date(),
487-
subjectID: z.string().regex(/^[^$]+$/, 'Subject ID has to be at least 1 character long and without a $')
487+
subjectID: z
488+
.string()
489+
.regex(/^[^$\s]+$/, 'Subject ID has to be at least 1 character long, without a $ and no whitespaces')
488490
});
489491

490492
shape = instrumentSchemaWithInternal._def.shape() as { [key: string]: z.ZodTypeAny };
491493
} else {
492494
instrumentSchemaWithInternal = instrumentSchema.extend({
493495
date: z.coerce.date(),
494-
subjectID: z.string().regex(/^[^$]+$/, 'Subject ID has to be at least 1 character long and without a $')
496+
subjectID: z.string().regex(/^[^$\s]+$/, 'Subject ID has to be at least 1 character long and without a $')
495497
});
496498
shape = instrumentSchemaWithInternal.shape as { [key: string]: z.ZodTypeAny };
497499
}
@@ -526,7 +528,7 @@ export async function processInstrumentCSV(
526528
const jsonLine: { [key: string]: unknown } = {};
527529
for (let j = 0; j < headers.length; j++) {
528530
const key = headers[j]!;
529-
const rawValue = elements[j]!;
531+
const rawValue = elements[j]!.trim();
530532

531533
if (rawValue === '\n') {
532534
continue;

0 commit comments

Comments
 (0)