diff --git a/cli/import.rs b/cli/import.rs index f996723f9..a339bd276 100644 --- a/cli/import.rs +++ b/cli/import.rs @@ -81,7 +81,8 @@ impl<'a> ImportFile<'a> { for r in record.iter() { values_string.push('\''); - values_string.push_str(r); + // The string can have a single quote which needs to be escaped + values_string.push_str(&r.replace("'", "''")); values_string.push_str("',"); } diff --git a/testing/shelltests.py b/testing/shelltests.py index 4fe43e837..0f9fc0b23 100755 --- a/testing/shelltests.py +++ b/testing/shelltests.py @@ -253,10 +253,10 @@ def test_import_csv(test_name: str, options: str, import_output: str, table_outp table_output, ) -test_import_csv('no_options', '--csv', '', '1|2.0|String1\n3|4.0|String2') +test_import_csv('no_options', '--csv', '', '1|2.0|String\'1\n3|4.0|String2') test_import_csv('verbose', '--csv -v', 'Added 2 rows with 0 errors using 2 lines of input' - ,'1|2.0|String1\n3|4.0|String2') + ,'1|2.0|String\'1\n3|4.0|String2') test_import_csv('skip', '--csv --skip 1', '' ,'3|4.0|String2') diff --git a/testing/test_files/test.csv b/testing/test_files/test.csv index 34a2e6cd7..718f5e212 100644 --- a/testing/test_files/test.csv +++ b/testing/test_files/test.csv @@ -1,2 +1,2 @@ -1,2.0,"String1" +1,2.0,"String'1" 3,4.0,"String2" \ No newline at end of file