fix: parse minimally-quoted csv rows when loading jobs.csv
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Parse one jobs.csv line. The file holds both fully-quoted rows (what
|
||||
// index.ts writes) and minimally-quoted ones (any tool that rewrites the CSV,
|
||||
// e.g. Python's csv module, only quotes fields containing a comma). Splitting
|
||||
// on '","' only understands the first form — every minimally-quoted row came
|
||||
// back with no link, so index.ts re-added old jobs as new and daily.ts
|
||||
// couldn't dedupe against them.
|
||||
export function parseCsvLine(line: string): string[] {
|
||||
const out: string[] = [];
|
||||
let cur = "";
|
||||
let quoted = false;
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const ch = line[i];
|
||||
if (quoted) {
|
||||
if (ch === '"' && line[i + 1] === '"') { cur += '"'; i++; }
|
||||
else if (ch === '"') quoted = false;
|
||||
else cur += ch;
|
||||
} else if (ch === '"') quoted = true;
|
||||
else if (ch === ",") { out.push(cur); cur = ""; }
|
||||
else cur += ch;
|
||||
}
|
||||
out.push(cur);
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user