Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
record_delimiter: fix multi bytes with skip_empty_lines and from_line
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 14, 2018
1 parent 7487424 commit 6fca318
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@

Fix:

* record_delimiter: fix multi bytes with skip_empty_lines and from_line
* rtrim: accept tab

## Version 4.1.0
Expand Down
2 changes: 2 additions & 0 deletions lib/es5/index.js
Expand Up @@ -458,6 +458,7 @@ function (_Transform) {
// Skip if line is empty and skip_empty_lines activated
if (skip_empty_lines === true && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0) {
this.info.empty_lines++;
pos += recordDelimiterLength - 1;
continue;
} // Activate records emition if above from_line

Expand All @@ -469,6 +470,7 @@ function (_Transform) {

this.__resetRow();

pos += recordDelimiterLength - 1;
continue;
} else {
var errField = this.__onField();
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -332,13 +332,15 @@ class Parser extends Transform {
// Skip if line is empty and skip_empty_lines activated
if(skip_empty_lines === true && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0){
this.info.empty_lines++
pos += recordDelimiterLength - 1
continue
}
// Activate records emition if above from_line
if(this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1: 0 ) >= from_line){
this.state.enabled = true
this.__resetField()
this.__resetRow()
pos += recordDelimiterLength - 1
continue
}else{
const errField = this.__onField()
Expand Down
12 changes: 11 additions & 1 deletion test/option.from_line.coffee
Expand Up @@ -59,7 +59,7 @@ describe 'Option `from_line`', ->
] unless err
next err

it 'not influenced by row delimiter', (next) ->
it 'not influenced by record delimiters', (next) ->
parse """
a,b,c:1,2,
3:d,e,f:4,5,
Expand All @@ -71,3 +71,13 @@ describe 'Option `from_line`', ->
[ '7','8','\n9' ]
] unless err
next err

it 'handle multiple bytes record delimiters', (next) ->
parse """
a,b\r\nc,d\r\ne,f
""", from_line: 2, (err, data) ->
data.should.eql [
[ 'c','d' ]
[ 'e','f' ]
] unless err
next err
10 changes: 10 additions & 0 deletions test/option.record_delimiter.coffee
Expand Up @@ -234,3 +234,13 @@ describe 'Option `record_delimiter`', ->
next err
parser.write c for c in '1,2,"\n"\r\n3,4,'
parser.end()

it 'with skip empty lines', (next) ->
parse """
ABC\r\n\r\nDEF\r\n\r\n
""", skip_empty_lines: true, (err, data) ->
data.should.eql [
[ 'ABC' ]
[ 'DEF' ]
] unless err
next err

0 comments on commit 6fca318

Please sign in to comment.