-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
CSVFileUtil.parseCSV(blob,boolean) doesn't correctly remove surrounding commas and fails to correctly parse line breaks in cells.
I wrote a custom test class for this utility (you can add it to your project)
@IsTest
public class CSVFileUtilTest {
@IsTest
static void testParseCsv() {
String csv =
'One,Two,Three\n'
+ 'Tree,"Dog",""House""\n'
+ '"""Quotes""","Commas,commas","Line\nbreak"\n';
List<String[]> actual = CSVFileUtil.parseCSV(Blob.valueOf(csv), false);
System.assertEquals(
new List<String[]>{
new String[]{'One','Two','Three'},
new String[]{'Tree','Dog','"House"'},
new String[]{'"Quotes"','Commas,commas','Line\nbreak'}
},
actual);
}
}
The result I get is:
System.AssertException: Assertion Failed: Expected: ((One, Two, Three), (Tree, Dog, "House"), ("Quotes", Commas,commas, Line
break)), Actual: ((One, Two, Three), (Tree, "Dog", "House"), (null,""Quotes"", "Commas,commas"), (null,break"))
Notice how "Dog" and "Commas,commas" should not be surrounded by quotes, and how "Line\nbreak" breaks the result (the first part is missing, and a couple null fields are added).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels