Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend/__tests__/csvParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
});
11 changes: 9 additions & 2 deletions frontend/lib/csvParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ export const parseCSV = (file: File): Promise<CsvData> => {
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;
}

Expand Down
Loading