[jira] [Commented] (CSV-228) CSVParser extracts columns wrong in case of space before quoted col name with comma
[ https://issues.apache.org/jira/browse/CSV-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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 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 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)
[jira] [Commented] (CSV-228) CSVParser extracts columns wrong in case of space before quoted col name with comma
[ https://issues.apache.org/jira/browse/CSV-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16864038#comment-16864038 ] Gary Gregory commented on CSV-228: -- We will need a reproducible test case, preferably in the form of a PR. See also {{org.apache.commons.csv.CSVFormat.withIgnoreSurroundingSpaces(boolean)}} > 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.3#76005)
[jira] [Commented] (CSV-228) CSVParser extracts columns wrong in case of space before quoted col name with comma
[ https://issues.apache.org/jira/browse/CSV-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16864034#comment-16864034 ] Sebb commented on CSV-228: -- According to my reading of RFC4180[1], the fields between delimiters are either either escaped or non-escaped. non-escaped fields can include spaces, but not comma escaped fields must start with the double-quote; leading spaces are not permitted. So I think the current behaviour is per specification, at least for the DEFAULT/RFC4180. [1] https://tools.ietf.org/html/rfc4180 > 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.3#76005)