Skip to content

Commit

Permalink
Merge pull request #13 from TransitApp/ilias/handleMultipleDoubleQuotes
Browse files Browse the repository at this point in the history
Fix: handle extra double quotes when empty value
  • Loading branch information
iliasbhal committed Feb 7, 2019
2 parents 5a5775f + b8bd978 commit b30f1eb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion helpers/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ function fromCsvStringToArray(string, tableName) {
}

if (!reValid.test(string)) {
if (string.match(/""""/)) {

if (string.match(/,"(("")+)",/) ) { // remove all extra double-quote if value should be -> ""
string = string.replace(/,"(("")+)",/g, ',"\\"\\"",');
return fromCsvStringToArray(string, tableName);
} else if (string.match(/""""/) ) {
string = string.replace(/""""/g, '\\"\\"');
return fromCsvStringToArray(string, tableName);
} else if (string.match(/,"""/)) { // Handle the case with 3 " at start/end of string
Expand All @@ -86,6 +90,7 @@ function fromCsvStringToArray(string, tableName) {
string = string.replace(/""/g, '\\"');
return fromCsvStringToArray(string, tableName);
}

process.notices.addWarning(__filename, `Row not valid in table ${tableName}: ${string}`);
return [];
}
Expand Down

0 comments on commit b30f1eb

Please sign in to comment.