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

Commit

Permalink
rowDelimiter: fix overlap with delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Oct 5, 2018
1 parent 391b708 commit 41b05bf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@

## Trunk

* rowDelimiter: fix overlap with delimiter
* internal: rename rowDelimiterLength to rowDelimiterMaxLength

## Version 3.1.2
Expand Down
6 changes: 3 additions & 3 deletions lib/es5/index.js
Expand Up @@ -745,10 +745,10 @@ Parser.prototype.__write = function (chars, end) {
this._.line.push(cast(this._.field || ''));

this._.closingQuote = 0;
this._.field = null;
this._.field = null; // End of field
// Ensure that the delimiter doesnt match as well the rowDelimiter

if (isDelimiter) {
// End of field
if (isDelimiter && !isRowDelimiter) {
i += this.options.delimiter.length;
this._.nextChar = chars.charAt(i);

Expand Down
4 changes: 3 additions & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/index.coffee.md
Expand Up @@ -412,7 +412,9 @@ Implementation of the [`stream.Transform` API](https://nodejs.org/api/stream.htm
@_.line.push cast @_.field or ''
@_.closingQuote = 0
@_.field = null
if isDelimiter # End of field
# End of field
# Ensure that the delimiter doesnt match as well the rowDelimiter
if isDelimiter and not isRowDelimiter
i += @options.delimiter.length
@_.nextChar = chars.charAt i
if end and not @_.nextChar
Expand Down
21 changes: 19 additions & 2 deletions test/options.rowDelimiter.coffee
Expand Up @@ -4,7 +4,7 @@ parse = require '../src'

describe 'options rowDelimiter', ->

it 'Test line breaks custom when rowDelimiter is a string', (next) ->
it 'as a string', (next) ->
parse """
ABC,45::DEF,23
""", rowDelimiter: '::', (err, data) ->
Expand All @@ -15,7 +15,7 @@ describe 'options rowDelimiter', ->
]
next()

it 'Test line breaks custom when rowDelimiter is an array', (next) ->
it 'as an array', (next) ->
parse """
ABC,45::DEF,23\n50,60
""", rowDelimiter: ['::','\n'], (err, data) ->
Expand All @@ -26,6 +26,23 @@ describe 'options rowDelimiter', ->
[ '50', '60']
]
next()

it 'ensure that delimiter and rowDelimiter doesnt match', (next) ->
parse """
a;b
11;22;
33;33;
""",
delimiter: ';'
rowDelimiter: [';\n', '\n']
, (err, data) ->
data.should.eql [
[ 'a', 'b' ]
[ '11', '22' ]
[ '33', '33' ]
] unless err
next err

it 'handle new line preceded by a quote when rowDelimiter is a string', (next) ->
parse """
Expand Down

0 comments on commit 41b05bf

Please sign in to comment.