haripriyamurthy / Deprecated-CustomMetadataLoader

Please refer the salesforce version of this tool
https://github.com/forcedotcom/CustomMetadataLoader
Other
21 stars 10 forks source link

Bad parsing of surrounding quotes and line breaks #12

Open pventurino opened 7 years ago

pventurino commented 7 years ago

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).

haripriyamurthy commented 7 years ago

@pventurino Can you please try the version on Force.com GitHub.