Skip to content

Commit

Permalink
Fix: handle extra double quotes when empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
iliasbhal committed Feb 6, 2019
1 parent 5a5775f commit 4f2eac5
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(/,"(("")+)",/g) ) { // remove all extra double-quote if value should be an empty string
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 4f2eac5

Please sign in to comment.