Skip to content

Commit

Permalink
adaltas#120: trailing whitespace and empty headers
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jan 9, 2017
1 parent 5530a73 commit c7a3a6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
25 changes: 11 additions & 14 deletions lib/index.js

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

11 changes: 5 additions & 6 deletions src/index.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ Implementation of the [`stream.Transform` API][transform]
{rowDelimiter: matchedRowDelimiter, matched: true}
else
{rowDelimiter: matchedRowDelimiter, matched: false}
ltrim = @options.trim or @options.ltrim
rtrim = @options.trim or @options.rtrim
chars = @buf + chars
Expand Down Expand Up @@ -423,11 +422,12 @@ Implementation of the [`stream.Transform` API][transform]
else
throw Error "Row delimiter(s) not found in the file #{JSON.stringify(@options.rowDelimiter)}"
# Flush remaining fields and lines
if end
if rtrim
@field = @field.trimRight() unless @closingQuote
if @field isnt ''
rtrimed = false
if rtrim and not @closingQuote
@field = @field.trimRight()
rtrimed = true
if @field isnt '' or rtrimed
@line.push auto_parse @field
@field = ''
if @field.length > @options.max_limit_on_data_read
Expand All @@ -439,7 +439,6 @@ Implementation of the [`stream.Transform` API][transform]
throw Error "Row delimiter(s) not found in the file #{JSON.stringify(@options.rowDelimiter[0])}"
else
throw Error "Row delimiter(s) not found in the file #{JSON.stringify(@options.rowDelimiter)}"
# Store un-parsed chars for next call
@buf = ''
while i < l
Expand Down
13 changes: 13 additions & 0 deletions test/options.trim.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ describe 'trim', ->
28392898392, 1974, 8.8392926E7," ABC DEF ", 23, 2050-11-27
"""
parser.end()

it 'with header and column count', (next) ->
parse 'h1,h2,h3, \n1,2,3, \n4,5,6, ',
delimiter: ','
columns: true
trim: true
, (err, data) ->
return next err if err
data.should.eql [
{ h1: '1', h2: '2', h3: '3', '': '' },
{ h1: '4', h2: '5', h3: '6', '': '' }
]
next()

it 'write aggressively', (next) ->
data = []
Expand Down

0 comments on commit c7a3a6e

Please sign in to comment.