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

Commit eee7e93

Browse files
committed
fix: handle empty column names properly
fix #275
1 parent f03c5f6 commit eee7e93

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Please join and contribute:
1919

2020
## Trunk
2121

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

lib/browser/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
10091009
var recordLength = record.length;
10101010

10111011
if (columns === true) {
1012-
if (isRecordEmpty(record)) {
1012+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
10131013
this.__resetRecord();
10141014

10151015
return;
@@ -1044,12 +1044,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
10441044
}
10451045
}
10461046

1047-
if (skip_lines_with_empty_values === true) {
1048-
if (isRecordEmpty(record)) {
1049-
this.__resetRecord();
1047+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
1048+
this.__resetRecord();
10501049

1051-
return;
1052-
}
1050+
return;
10531051
}
10541052

10551053
if (this.state.recordHasError === true) {

lib/browser/sync.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
10091009
var recordLength = record.length;
10101010

10111011
if (columns === true) {
1012-
if (isRecordEmpty(record)) {
1012+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
10131013
this.__resetRecord();
10141014

10151015
return;
@@ -1044,12 +1044,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
10441044
}
10451045
}
10461046

1047-
if (skip_lines_with_empty_values === true) {
1048-
if (isRecordEmpty(record)) {
1049-
this.__resetRecord();
1047+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
1048+
this.__resetRecord();
10501049

1051-
return;
1052-
}
1050+
return;
10531051
}
10541052

10551053
if (this.state.recordHasError === true) {

lib/es5/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ var Parser = /*#__PURE__*/function (_Transform) {
901901
var recordLength = record.length;
902902

903903
if (columns === true) {
904-
if (isRecordEmpty(record)) {
904+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
905905
this.__resetRecord();
906906

907907
return;
@@ -936,12 +936,10 @@ var Parser = /*#__PURE__*/function (_Transform) {
936936
}
937937
}
938938

939-
if (skip_lines_with_empty_values === true) {
940-
if (isRecordEmpty(record)) {
941-
this.__resetRecord();
939+
if (skip_lines_with_empty_values === true && isRecordEmpty(record)) {
940+
this.__resetRecord();
942941

943-
return;
944-
}
942+
return;
945943
}
946944

947945
if (this.state.recordHasError === true) {

lib/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ class Parser extends Transform {
704704
if(err !== undefined) return err
705705
}
706706
}
707-
708707
const lappend = ltrim === false || this.state.quoting === true || this.state.field.length !== 0 || !this.__isCharTrimable(chr)
709708
// rtrim in non quoting is handle in __onField
710709
const rappend = rtrim === false || this.state.wasQuoting === false
@@ -761,7 +760,7 @@ class Parser extends Transform {
761760
// Convert the first line into column names
762761
const recordLength = record.length
763762
if(columns === true){
764-
if(isRecordEmpty(record)){
763+
if(skip_lines_with_empty_values === true && isRecordEmpty(record)){
765764
this.__resetRecord()
766765
return
767766
}
@@ -802,11 +801,9 @@ class Parser extends Transform {
802801
if(finalErr) return finalErr
803802
}
804803
}
805-
if(skip_lines_with_empty_values === true){
806-
if(isRecordEmpty(record)){
807-
this.__resetRecord()
808-
return
809-
}
804+
if(skip_lines_with_empty_values === true && isRecordEmpty(record)){
805+
this.__resetRecord()
806+
return
810807
}
811808
if(this.state.recordHasError === true){
812809
this.__resetRecord()

test/option.columns.coffee

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ describe 'Option `columns`', ->
7676
{a: '7', b: '6', c: '8'}
7777
] unless err
7878
next err
79+
80+
it 'lines with empty column names', (next) ->
81+
parse '''
82+
,,,
83+
1,2,3,4
84+
5,6,7,8
85+
''', columns: true, (err, data) ->
86+
data.should.eql [
87+
{'': '4'}
88+
{'': '8'}
89+
] unless err
90+
next err
7991

8092
describe 'boolean', ->
8193

0 commit comments

Comments
 (0)