Skip to content

Commit 253666d

Browse files
authored
Fix csv splitter when skipping empty lines (#6586)
Signed-off-by: Ben Sherman <[email protected]>
1 parent 064ef34 commit 253666d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

modules/nextflow/src/main/groovy/nextflow/splitter/CsvSplitter.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class CsvSplitter extends AbstractTextSplitter {
129129
String line
130130
int z = 0
131131

132-
while( z++ < skipLines && reader.readLine()) { /* nope */ }
132+
while( z++ < skipLines && reader.readLine() != null ) { /* nope */ }
133133

134134
if( firstLineAsHeader ) {
135135
line = reader.readLine()

modules/nextflow/src/test/groovy/nextflow/splitter/CsvSplitterTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ class CsvSplitterTest extends Specification {
9090
items[0] == ['gamma', '', 'zeta']
9191
items[1] == ['eta', 'theta', 'iota']
9292
items[2] == ['mu', 'nu', 'xi']
93+
94+
when:
95+
def LINES = '''
96+
alpha,beta,delta
97+
98+
gamma,,zeta
99+
eta,theta,iota
100+
pi,rho,sigma
101+
'''
102+
.stripIndent().trim()
103+
items = new CsvSplitter().target(LINES).options(skip:3).list()
104+
then:
105+
items.size() == 2
106+
items[0] instanceof List
107+
items[0] == ['eta', 'theta', 'iota']
108+
items[1] == ['pi', 'rho', 'sigma']
93109
}
94110

95111
def testSplitWithCount() {

0 commit comments

Comments
 (0)