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

Commit

Permalink
fix: handle empty column names properly
Browse files Browse the repository at this point in the history
fix #275
  • Loading branch information
wdavidw committed Apr 26, 2021
1 parent f03c5f6 commit eee7e93
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ Please join and contribute:

## Trunk

* fix: handle empty column names properly
* feat: enforce usage of columns with columns_duplicates_to_array
* fix: update error message with invalid column type

Expand Down
10 changes: 4 additions & 6 deletions lib/browser/index.js
Expand Up @@ -1009,7 +1009,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
var recordLength = record.length;

if (columns === true) {
if (isRecordEmpty(record)) {
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
Expand Down Expand Up @@ -1044,12 +1044,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
}
}

if (skip_lines_with_empty_values === true) {
if (isRecordEmpty(record)) {
this.__resetRecord();
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
}
return;
}

if (this.state.recordHasError === true) {
Expand Down
10 changes: 4 additions & 6 deletions lib/browser/sync.js
Expand Up @@ -1009,7 +1009,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
var recordLength = record.length;

if (columns === true) {
if (isRecordEmpty(record)) {
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
Expand Down Expand Up @@ -1044,12 +1044,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
}
}

if (skip_lines_with_empty_values === true) {
if (isRecordEmpty(record)) {
this.__resetRecord();
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
}
return;
}

if (this.state.recordHasError === true) {
Expand Down
10 changes: 4 additions & 6 deletions lib/es5/index.js
Expand Up @@ -901,7 +901,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
var recordLength = record.length;

if (columns === true) {
if (isRecordEmpty(record)) {
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
Expand Down Expand Up @@ -936,12 +936,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
}
}

if (skip_lines_with_empty_values === true) {
if (isRecordEmpty(record)) {
this.__resetRecord();
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
this.__resetRecord();

return;
}
return;
}

if (this.state.recordHasError === true) {
Expand Down
11 changes: 4 additions & 7 deletions lib/index.js
Expand Up @@ -704,7 +704,6 @@ class Parser extends Transform {
if(err !== undefined) return err
}
}

const lappend = ltrim === false || this.state.quoting === true || this.state.field.length !== 0 || !this.__isCharTrimable(chr)
// rtrim in non quoting is handle in __onField
const rappend = rtrim === false || this.state.wasQuoting === false
Expand Down Expand Up @@ -761,7 +760,7 @@ class Parser extends Transform {
// Convert the first line into column names
const recordLength = record.length
if(columns === true){
if(isRecordEmpty(record)){
if(skip_lines_with_empty_values === true && isRecordEmpty(record)){
this.__resetRecord()
return
}
Expand Down Expand Up @@ -802,11 +801,9 @@ class Parser extends Transform {
if(finalErr) return finalErr
}
}
if(skip_lines_with_empty_values === true){
if(isRecordEmpty(record)){
this.__resetRecord()
return
}
if(skip_lines_with_empty_values === true && isRecordEmpty(record)){
this.__resetRecord()
return
}
if(this.state.recordHasError === true){
this.__resetRecord()
Expand Down
12 changes: 12 additions & 0 deletions test/option.columns.coffee
Expand Up @@ -76,6 +76,18 @@ describe 'Option `columns`', ->
{a: '7', b: '6', c: '8'}
] unless err
next err

it 'lines with empty column names', (next) ->
parse '''
,,,
1,2,3,4
5,6,7,8
''', columns: true, (err, data) ->
data.should.eql [
{'': '4'}
{'': '8'}
] unless err
next err

describe 'boolean', ->

Expand Down

0 comments on commit eee7e93

Please sign in to comment.