Skip to content

Commit 1d6b817

Browse files
authored
Fix CSV quote handling. (#401)
* fix: Fix CSV quote handling. * chore: Refine test case.
1 parent 59417cc commit 1d6b817

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/format/stream/delimited-text-stream.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ export function delimitedTextTransformer(delimiter = ',') {
5353
if (++qc === 3) {
5454
// consume escaped quote char ("")
5555
qc = 1;
56-
} else if (++I < N && chunk.charCodeAt(I) !== QUOTE) {
56+
} else if ((I + 1) < N && chunk.charCodeAt(I + 1) !== QUOTE) {
5757
qc = 0; // reset quote char count
5858
q = true; // reached end of quote
59+
++I;
5960
break;
6061
}
6162
}
@@ -148,7 +149,9 @@ export function delimitedTextTransformer(delimiter = ',') {
148149

149150
flush(controller) {
150151
if (row.length || fragment) {
151-
if (fragment != null) row.push(fragment);
152+
if (fragment != null) {
153+
row.push(qc === 2 ? unquote(fragment) : fragment);
154+
}
152155
controller.enqueue([row]);
153156
}
154157
}

test/format/from-csv-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ function csvTests(name, parseCSV) {
150150
const csvLoad = await parseCSV(csv);
151151
assert.strictEqual(csvLoad.numRows(), numRows);
152152
assert.strictEqual(csvLoad.numCols(), numCols);
153+
154+
// test embedded map
155+
const map = '{"0"=>"https://web.site", "1"=>"https://other.site.com/"}';
156+
const mapData = { id: [1, 2], map: [map, map] };
157+
tableEqual(
158+
await parseCSV(table(mapData).toCSV()),
159+
mapData,
160+
'csv parsed map data'
161+
);
153162
});
154163
});
155164
}

0 commit comments

Comments
 (0)