Skip to content

Commit d80a832

Browse files
authored
Merge branch 'master' into fix/csvprinter-reader-quote-escape
2 parents 68b4b09 + 2712665 commit d80a832

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ Getting Started
4848
---------------
4949

5050
+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
51-
+ Make sure you have a [GitHub account](https://github.com/signup/free). This is not essential, but makes providing patches much easier.
51+
+ Make sure you have a [GitHub account](https://github.com/signup). This is not essential, but makes providing patches much easier.
5252
+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons CSV's scope.
5353
+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist.
5454
+ Clearly describe the issue including steps to reproduce when it is a bug.
5555
+ Make sure you fill in the earliest version that you know has the issue.
5656
+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-),
57-
[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. If you don't have a GitHub account, you can still clone the Commons repository.
57+
[fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) and check out your forked repository. If you don't have a GitHub account, you can still clone the Commons repository.
5858

5959
Making Changes
6060
--------------
@@ -108,8 +108,8 @@ Additional Resources
108108
+ [Contributing patches](https://commons.apache.org/patches.html)
109109
+ [Apache Commons CSV JIRA project page][jira]
110110
+ [Contributor License Agreement][cla]
111-
+ [General GitHub documentation](https://help.github.com/)
112-
+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/)
111+
+ [General GitHub documentation](https://docs.github.com/)
112+
+ [GitHub pull request documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
113113
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
114114

115115
[cla]:https://www.apache.org/licenses/#clas

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>org.apache.commons</groupId>
2222
<artifactId>commons-parent</artifactId>
23-
<version>101</version>
23+
<version>102</version>
2424
</parent>
2525
<artifactId>commons-csv</artifactId>
2626
<version>1.15.0-SNAPSHOT</version>

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@
5252
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-324">Lexer.isDelimiter() accepts a partial multi-character delimiter at EOF (#603).</action>
5353
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-325">CSVParser applies characterOffset to bytePosition (#604).</action>
5454
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-326">CSVPrinter Reader printing with quote and escape can emit CSV that its parser cannot read back.</action>
55+
<action type="fix" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-327">CSVParser applies maxRows to record numbers instead of rows produced when setRecordNumber(...) is used.</action>
5556
<!-- ADD -->
5657
<action type="add" dev="ggregory" due-to="Gary Gregory, Indy, Sylvia van Os" issue="CSV-307">Add an "Android Compatibility" section to the web site.</action>
5758
<action type="add" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory" issue="CSV-325">Add CSVParser.Builder.setByteOffset(long) (#604).</action>
5859
<!-- UPDATE -->
59-
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 101 #573, #595.</action>
60+
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 102 #573, #595.</action>
6061
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[test] Bump com.opencsv:opencsv from 5.11.2 to 5.12.0 #558.</action>
6162
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-lang3 from 3.18.0 to 3.20.0.</action>
6263
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-codec:commons-codec from 1.19.0 to 1.22.0.</action>

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public Builder setTrackBytes(final boolean trackBytes) {
237237

238238
final class CSVRecordIterator implements Iterator<CSVRecord> {
239239
private CSVRecord current;
240+
private long recordCount;
240241

241242
/**
242243
* Gets the next record or null at the end of stream or max rows read.
@@ -247,8 +248,11 @@ final class CSVRecordIterator implements Iterator<CSVRecord> {
247248
*/
248249
private CSVRecord getNextRecord() {
249250
CSVRecord record = null;
250-
if (format.useRow(recordNumber + 1)) {
251+
if (format.useRow(recordCount + 1)) {
251252
record = Uncheck.get(CSVParser.this::nextRecord);
253+
if (record != null) {
254+
recordCount++;
255+
}
252256
}
253257
return record;
254258
}

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,23 @@ void testGetRecordsMaxRows(final long maxRows) throws IOException {
965965
}
966966
}
967967

968+
/**
969+
* Tests <a href="https://issues.apache.org/jira/browse/CSV-327">CSV-327</a>.
970+
*/
971+
@Test
972+
void testGetRecordsMaxRowsWithRecordNumberOffset() throws IOException {
973+
try (CSVParser parser = CSVParser.builder()
974+
.setReader(new StringReader("a,b\nc,d\n"))
975+
.setFormat(CSVFormat.DEFAULT.builder().setMaxRows(1).get())
976+
.setRecordNumber(2)
977+
.get()) {
978+
final List<CSVRecord> records = parser.getRecords();
979+
assertEquals(1, records.size());
980+
assertEquals(2, records.get(0).getRecordNumber());
981+
assertValuesEquals(new String[] { "a", "b" }, records.get(0));
982+
}
983+
}
984+
968985
@Test
969986
void testGetRecordThreeBytesRead() throws Exception {
970987
final String code = "id,date,val5,val4\n" +

0 commit comments

Comments
 (0)