Open pventurino opened 7 years ago
CSVFileUtil.parseCSV(blob,boolean) doesn't correctly remove surrounding commas and fails to correctly parse line breaks in cells.
CSVFileUtil.parseCSV(blob,boolean)
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).
null
@pventurino Can you please try the version on Force.com GitHub.
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)
The result I get is:
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).