Skip to content

Commit

Permalink
fix(csv-parse): comment infix when comment first field char (fix #415)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 28, 2024
1 parent 6575fc6 commit 8e0f8b8
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 38 deletions.
2 changes: 1 addition & 1 deletion demo/issues-esm/lib/415.js
Expand Up @@ -13,7 +13,7 @@ await pipeline(
parse({
comment: "#",
delimiter: "\t",
relax_column_count: true,
comment_no_infix: true
}),
stringify({ delimiter: "|" }),
process.stdout
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/cjs/index.cjs
Expand Up @@ -847,10 +847,12 @@ const transform = function(original_options = {}) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/cjs/sync.cjs
Expand Up @@ -845,10 +845,12 @@ const transform = function(original_options = {}) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/esm/index.js
Expand Up @@ -5969,10 +5969,12 @@ const transform = function(original_options = {}) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/esm/sync.js
Expand Up @@ -2815,10 +2815,12 @@ const transform = function(original_options = {}) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/iife/index.js
Expand Up @@ -5972,10 +5972,12 @@ var csv_parse = (function (exports) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/iife/sync.js
Expand Up @@ -2818,10 +2818,12 @@ var csv_parse_sync = (function (exports) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/umd/index.js
Expand Up @@ -5975,10 +5975,12 @@
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/dist/umd/sync.js
Expand Up @@ -2821,10 +2821,12 @@
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
10 changes: 6 additions & 4 deletions packages/csv-parse/lib/api/index.js
Expand Up @@ -259,10 +259,12 @@ const transform = function(original_options = {}) {
if(this.state.commenting){
continue;
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0 && (comment_no_infix === false || this.state.field.length === 0)){
this.state.commenting = true;
continue;
if(comment !== null && (comment_no_infix === false || (this.state.record.length === 0 && this.state.field.length === 0))) {
const commentCount = this.__compareBytes(comment, buf, pos, chr);
if(commentCount !== 0){
this.state.commenting = true;
continue;
}
}
const delimiterLength = this.__isDelimiter(buf, pos, chr);
if(delimiterLength !== 0){
Expand Down
11 changes: 10 additions & 1 deletion packages/csv-parse/test/option.comment_no_infix.coffee
Expand Up @@ -19,7 +19,16 @@ describe 'Option `comment_no_infix`', ->
message: 'Invalid option comment_no_infix: value must be a boolean, got 2'
code: 'CSV_INVALID_OPTION_COMMENT'

it 'with `true`', (next) ->
it 'with `true`, field starting with comment', (next) ->
parse '''
a,#,c
''', comment: '#', comment_no_infix: true, (err, records) ->
records.should.eql [
['a', '#', 'c']
] unless err
next err

it 'with `true`, field not starting with comment', (next) ->
parse '''
a,b#,c
''', comment: '#', comment_no_infix: true, (err, records) ->
Expand Down

0 comments on commit 8e0f8b8

Please sign in to comment.