Skip to content

Commit 0aa9c47

Browse files
committed
[CSV-254] POSTGRESQL_CSV cannot parse correctly (null vs zero-length
string) Add test
1 parent 6bbb815 commit 0aa9c47

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<exclude>src/test/resources/org/apache/commons/csv/CSV-196/emoji.csv</exclude>
184184
<exclude>src/test/resources/org/apache/commons/csv/CSV-196/japanese.csv</exclude>
185185
<exclude>src/test/resources/org/apache/commons/csv/CSV-213/999751170.patch.csv</exclude>
186+
<exclude>src/test/resources/org/apache/commons/csv/CSV-254/csv-254.csv</exclude>
186187
<exclude>src/test/resources/org/apache/commons/csv/CSVFileParser/bom.csv</exclude>
187188
<exclude>src/test/resources/org/apache/commons/csv/CSVFileParser/test.csv</exclude>
188189
<exclude>src/test/resources/org/apache/commons/csv/CSVFileParser/test_default.txt</exclude>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.commons.csv.issues;
21+
22+
import static org.apache.commons.csv.CsvAssertions.assertValuesEquals;
23+
24+
import java.io.BufferedReader;
25+
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
27+
import java.nio.file.Files;
28+
import java.nio.file.Paths;
29+
import java.util.Iterator;
30+
31+
import org.apache.commons.csv.CSVFormat;
32+
import org.apache.commons.csv.CSVParser;
33+
import org.apache.commons.csv.CSVRecord;
34+
import org.junit.jupiter.api.Test;
35+
36+
/**
37+
* Tests https://issues.apache.org/jira/browse/CSV-254.
38+
*/
39+
class JiraCsv254Test {
40+
41+
@Test
42+
void test() throws IOException {
43+
final CSVFormat csvFormat = CSVFormat.POSTGRESQL_CSV;
44+
try (BufferedReader reader = Files.newBufferedReader(Paths.get("src/test/resources/org/apache/commons/csv/CSV-254/csv-254.csv"),
45+
StandardCharsets.UTF_8); CSVParser parser = csvFormat.parse(reader)) {
46+
final Iterator<CSVRecord> csvRecords = parser.iterator();
47+
assertValuesEquals(new String[] { "AA", "33", null }, csvRecords.next());
48+
assertValuesEquals(new String[] { "AA", null, "" }, csvRecords.next());
49+
assertValuesEquals(new String[] { null, "33", "CC" }, csvRecords.next());
50+
}
51+
}
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AA,33,
2+
AA,,""
3+
,33,CC

0 commit comments

Comments
 (0)