commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Herbert (Jira)" <j...@apache.org>
Subject [jira] [Comment Edited] (CSV-247) A single empty header is allowed when not allowing empty column headers.
Date Mon, 07 Oct 2019 13:05:00 GMT

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

Alex Herbert edited comment on CSV-247 at 10/7/19 1:04 PM:
-----------------------------------------------------------

I still think there is an inconsistency.

My original test case in the ticket header expects an exception when there is a single missing
header and the parser is configured to not allow missing column names.

This is how the code works. This runs fine against current master:
{code:java}
@Test
public void testHeadersMissing() throws Exception {
    final CSVFormat format = CSVFormat.DEFAULT.withHeader();

    // The default does not allow missing column names but allows
    // duplicate headers
    Assertions.assertFalse(format.getAllowMissingColumnNames(),
        "By default we should not allow missing column names");
    Assertions.assertTrue(format.getAllowDuplicateHeaderNames(),
        "By default we should allow duplicate column names");

    Assertions.assertDoesNotThrow(() -> {
        final Reader in = new StringReader("a,,c,d,e\n1,2,3,4,5\nv,w,x,y,z");
        format.parse(in).iterator();
    }, "1 missing column header is OK");

    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        final Reader in = new StringReader("a,,c,d,\n1,2,3,4,5\nv,w,x,y,z");
        format.parse(in).iterator();
    }, "2+ missing column headers is not allowed!");
}
{code}
So 1 missing header is fine but not 2 or more. This is the bug.

My PR to fix this is old. Do you want a rebased version with tests showing what I expect?

 


was (Author: alexherbert):
I still think there is an inconsistency.

My original test case in the ticket header expects an exception when there is a single missing
header and the parser is configured to not allow missing column names.

This is how the code works. This runs fine against current master:
{code:java}
@Test
public void testHeadersMissing() throws Exception {
    final CSVFormat parser = CSVFormat.DEFAULT.withHeader();

    // The default does not allow missing column names but allows
    // duplicate headers
    Assertions.assertFalse(parser.getAllowMissingColumnNames(),
        "By default we should not allow missing column names");
    Assertions.assertTrue(parser.getAllowDuplicateHeaderNames(),
        "By default we should allow duplicate column names");

    Assertions.assertDoesNotThrow(() -> {
        final Reader in = new StringReader("a,,c,d,e\n1,2,3,4,5\nv,w,x,y,z");
        parser.parse(in).iterator();
    }, "1 missing column header is OK");

    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        final Reader in = new StringReader("a,,c,d,\n1,2,3,4,5\nv,w,x,y,z");
        parser.parse(in).iterator();
    }, "2+ missing column headers is not allowed!");
}
{code}
So 1 missing header is fine but not 2 or more. This is the bug.

My PR to fix this is old. Do you want a rebased version with tests showing what I expect?

 

> A single empty header is allowed when not allowing empty column headers.
> ------------------------------------------------------------------------
>
>                 Key: CSV-247
>                 URL: https://issues.apache.org/jira/browse/CSV-247
>             Project: Commons CSV
>          Issue Type: Bug
>    Affects Versions: 1.7
>            Reporter: Alex Herbert
>            Priority: Minor
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> If the settings are not allowing empty columns headers you can currently use a single
empty header. This is because column headers are only checked for empty when they are duplicates.
So it is the second empty header (the first duplicate) that raises an error. This test should
pass but does not:
> {code:java}
> @Test(expected = IllegalArgumentException.class)
> public void testHeadersMissingOneColumnException() throws Exception {
>     final Reader in = new StringReader("a,,c,d\n1,2,3,4\nx,y,z,zz");    CSVFormat.DEFAULT.withHeader().parse(in).iterator();

> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message