[ 
https://issues.apache.org/jira/browse/CSV-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16909103#comment-16909103
 ] 

Aljoscha Rittner commented on CSV-228:
--------------------------------------

As [~ggregory] mentioned, the flag {{withIgnoreSurroundingSpaces (true)}} works 
as expected. In my opinion it's not a bug.

Without {{withIgnoreSurroundingSpaces (true)}}
{code:java}
    @Test
    public void testFailureOnEmptyCharactersBetweenDelimiters2 () throws 
IOException {
        CSVParser csvParser = CSVFormat.DEFAULT
            .withTrim ()
            .parse ( new StringReader ( "Sample , \"FOO, BAR BAZ\"" ) );

        List<CSVRecord> records = csvParser.getRecords ();

        assertThat ( records, notNullValue () );
        assertThat ( records.size (), equalTo ( 1 ) );

        CSVRecord record = records.get ( 0 );

        assertThat ( record.size (), equalTo ( 3 ) );

        assertThat ( record.get ( 0 ), equalTo ( "Sample" ) );
        assertThat ( record.get ( 1 ), equalTo ( "\"FOO" ) );
        assertThat ( record.get ( 2 ), equalTo ( "BAR BAZ\"" ) );
    }
{code}
With {{withIgnoreSurroundingSpaces (true)}} (and the result [~achugr] wants):
{code:java}
    @Test
    public void 
testOnEmptyCharactersBetweenDelimitersWithIgnoreSurroundingSpaces () throws 
IOException {
        CSVParser csvParser = CSVFormat.DEFAULT
            .withTrim ()
            .withIgnoreSurroundingSpaces ()
            .parse ( new StringReader ( "Sample , \"FOO, BAR BAZ\"" ) );

        List<CSVRecord> records = csvParser.getRecords ();

        assertThat ( records, notNullValue () );
        assertThat ( records.size (), equalTo ( 1 ) );

        CSVRecord record = records.get ( 0 );

        assertThat ( record.size (), equalTo ( 2 ) );

        assertThat ( record.get ( 0 ), equalTo ( "Sample" ) );
        assertThat ( record.get ( 1 ), equalTo ( "FOO, BAR BAZ" ) );
    }{code}

> CSVParser extracts columns wrong in case of space before quoted col name with 
> comma
> -----------------------------------------------------------------------------------
>
>                 Key: CSV-228
>                 URL: https://issues.apache.org/jira/browse/CSV-228
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.4
>            Reporter: Artemii Chugreev
>            Priority: Minor
>
> CSV header is something like
> col name 1, "col name 2, with comma", col name 3
> CSVParser#getHeadersMap returns 4 columns, because of space before second 
> column name which breaks quoting



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to