Skip to content

Commit 23c4f00

Browse files
committed
fix(reducer-gtfsplus): fix column parsing for gtfsplus csv
1 parent 46b3c9a commit 23c4f00

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/gtfsplus/reducers/gtfsplus.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@ const gtfsplus = (state = {
3333
case 'RECEIVE_GTFSPLUS_CONTENT':
3434
const newTableData = {}
3535
for (let i = 0; i < action.filenames.length; i++) {
36+
// split file into lines
3637
const lines = action.fileContent[i].split(/\r\n|\r|\n/g)
3738
if (lines.length < 2) continue
38-
// console.log(lines[0])
3939
const fields = lines[0].split(',')
40-
// console.log(fields)
41-
// console.log(fields[fields.length - 1])
40+
const COLUMN_REGEX = /,(?=(?:(?:[^"]*"){2})*[^"]*$)/
4241
const tableName = action.filenames[i].split('.')[0]
4342
newTableData[tableName] = lines.slice(1)
44-
.filter(line => line.split(',').length === fields.length)
43+
.filter(line => line.split(COLUMN_REGEX).length === fields.length)
4544
.map((line, rowIndex) => {
46-
const values = line.split(',')
45+
const values = line.split(COLUMN_REGEX)
4746
const rowData = { origRowIndex: rowIndex }
4847
for (let f = 0; f < fields.length; f++) {
4948
rowData[fields[f]] = values[f]

0 commit comments

Comments
 (0)