diff --git a/frontend/__tests__/csvParser.test.ts b/frontend/__tests__/csvParser.test.ts index ae5c88d..1d8202b 100644 --- a/frontend/__tests__/csvParser.test.ts +++ b/frontend/__tests__/csvParser.test.ts @@ -59,4 +59,17 @@ describe('parseCSV', () => { expect(result.headers).toEqual(['a', 'b', 'c']); expect(result.rows).toEqual([]); }); + + it('parses a single-column CSV (no delimiter character anywhere)', async () => { + // Mirrors test_symbols_failed.csv: header + tickers, CRLF line endings, + // no commas/tabs/pipes/semicolons. PapaParse can't auto-detect a delimiter + // and emits an "UndetectableDelimiter" warning; the data still parses fine. + const csv = 'Symbol\r\nAMZN\r\nCRSR\r\nAMD\r\nMSFT\r\n0700.HK\r\n'; + const result = await parseCSV(fileFromString(csv)); + + expect(result.headers).toEqual(['Symbol']); + expect(result.rows).toHaveLength(5); + expect(result.rows[0]).toEqual({ Symbol: 'AMZN' }); + expect(result.rows[4]).toEqual({ Symbol: '0700.HK' }); + }); }); diff --git a/frontend/lib/csvParser.ts b/frontend/lib/csvParser.ts index c3626c4..3b2c35b 100644 --- a/frontend/lib/csvParser.ts +++ b/frontend/lib/csvParser.ts @@ -8,8 +8,15 @@ export const parseCSV = (file: File): Promise => { dynamicTyping: true, skipEmptyLines: true, complete: (results) => { - if (results.errors.length > 0) { - reject(new Error(results.errors[0].message)); + // PapaParse emits a non-fatal "UndetectableDelimiter" warning when the + // sample contains none of `,` `\t` `|` `;` (e.g. a single-column CSV). + // The data still parses correctly using the default `,` delimiter, + // so this warning is informational — drop it before deciding to reject. + const fatalErrors = results.errors.filter( + (e) => !(e.type === 'Delimiter' && e.code === 'UndetectableDelimiter') + ); + if (fatalErrors.length > 0) { + reject(new Error(fatalErrors[0].message)); return; }