diff --git a/CHANGELOG.md b/CHANGELOG.md index 79dfe9b..a34ec20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ * promise: new API module * errors: finish normalisation of all errors +## Trunk + +* errors: don't stringify/parse undefined and null values +* errors: expose CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE +* errors: expose CSV_MAX_RECORD_SIZE + ## Version 4.6.3 * lint: integrate eslint diff --git a/lib/es5/index.js b/lib/es5/index.js index 1ea9e42..ae57d8a 100644 --- a/lib/es5/index.js +++ b/lib/es5/index.js @@ -1216,8 +1216,8 @@ function (_Error) { var context = _contexts[_i2]; for (var key in context) { - var value = Buffer.isBuffer(context[key]) ? context[key].toString() : context[key]; - _this2[key] = JSON.parse(JSON.stringify(value)); + var value = context[key]; + _this2[key] = Buffer.isBuffer(value) ? value.toString() : value == null ? value : JSON.parse(JSON.stringify(value)); } } diff --git a/lib/index.js b/lib/index.js index e1d51f3..3106e08 100644 --- a/lib/index.js +++ b/lib/index.js @@ -969,8 +969,8 @@ class CsvError extends Error { this.code = code for(const context of contexts){ for(const key in context){ - const value = Buffer.isBuffer(context[key]) ? context[key].toString() : context[key] - this[key] = JSON.parse(JSON.stringify(value)) + const value = context[key] + this[key] = Buffer.isBuffer(value) ? value.toString() : value == null ? value : JSON.parse(JSON.stringify(value)) } } } diff --git a/test/option.columns.coffee b/test/option.columns.coffee index 8b94954..bb25f29 100644 --- a/test/option.columns.coffee +++ b/test/option.columns.coffee @@ -181,6 +181,19 @@ describe 'Option `columns`', -> { a: '3' } ] unless err next err + + it '', (next) -> + # Trigger a bug where error is try to stringify and parse an undefined + # value, conjointly triggered by a null column and a + # CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS error + parse """ + col_a,col_b,col_c + foo,bar + foo,bar,baz + """ + , columns: ['a', 'b', null], (err, data) -> + err.code.should.eql 'CSV_INVALID_RECORD_LENGTH_DONT_MATCH_COLUMNS' + next() describe 'function', -> diff --git a/test/option.skip_lines_with_error.coffee b/test/option.skip_lines_with_error.coffee index dad325f..9f9d70d 100644 --- a/test/option.skip_lines_with_error.coffee +++ b/test/option.skip_lines_with_error.coffee @@ -46,6 +46,7 @@ describe 'Option `skip_lines_with_error`', -> ["line","1"] ["line", "3"] ] unless err + console.log errors assert_error errors, [ message: 'Invalid Opening Quote: a quote is found inside a field at line 2' code: 'INVALID_OPENING_QUOTE'