diff --git a/gnucash/import-export/csv-imp/gnc-tokenizer-csv.cpp b/gnucash/import-export/csv-imp/gnc-tokenizer-csv.cpp index b5ad206feb..bb4f8c89ff 100644 --- a/gnucash/import-export/csv-imp/gnc-tokenizer-csv.cpp +++ b/gnucash/import-export/csv-imp/gnc-tokenizer-csv.cpp @@ -76,6 +76,16 @@ int GncCsvTokenizer::tokenize() bs_pos = line.find ('\\', bs_pos); } + // Deal with repeated " ("") in strings. + // This is commonly used as escape mechanism for double quotes in csv files. + // However boost just eats them. + bs_pos = line.find ("\"\""); + while (bs_pos != std::string::npos) + { + line.replace (bs_pos, 2, "\\\""); + bs_pos = line.find ("\"\""); + } + Tokenizer tok(line, sep); vec.assign(tok.begin(),tok.end()); m_tokenized_contents.push_back(vec); diff --git a/gnucash/import-export/csv-imp/test/test-tokenizer.cpp b/gnucash/import-export/csv-imp/test/test-tokenizer.cpp index fdbd1e10d4..961ac65cd3 100644 --- a/gnucash/import-export/csv-imp/test/test-tokenizer.cpp +++ b/gnucash/import-export/csv-imp/test/test-tokenizer.cpp @@ -176,6 +176,7 @@ static tokenize_csv_test_data comma_separated [] = { { "05/01/15,45,Acme Inc.,,Miscellaneous,", 6, { "05/01/15","45","Acme Inc.","","Miscellaneous","",NULL,NULL } }, { "Test\\ with backslash,nextfield", 2, { "Test\\ with backslash","nextfield",NULL,NULL,NULL,NULL,NULL,NULL } }, { "Test with \\\" escaped quote,nextfield", 2, { "Test with \" escaped quote","nextfield",NULL,NULL,NULL,NULL,NULL,NULL } }, + { "Test with \"\" escaped quote,nextfield", 2, { "Test with \" escaped quote","nextfield",NULL,NULL,NULL,NULL,NULL,NULL } }, { NULL, 0, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }, };