@@ -5385,12 +5385,40 @@ var csv_parse_sync = (function (exports) {
5385
5385
throw new Error ( `Invalid Option: raw must be true, got ${ JSON . stringify ( options . raw ) } ` ) ;
5386
5386
}
5387
5387
// Normalize option `record_delimiter`
5388
- if ( ! options . record_delimiter ) {
5388
+ if ( options . record_delimiter === undefined ) {
5389
5389
options . record_delimiter = [ ] ;
5390
- } else if ( ! Array . isArray ( options . record_delimiter ) ) {
5390
+ } else if ( typeof options . record_delimiter === 'string' || isBuffer ( options . record_delimiter ) ) {
5391
+ if ( options . record_delimiter . length === 0 ) {
5392
+ throw new CsvError ( 'CSV_INVALID_OPTION_RECORD_DELIMITER' , [
5393
+ 'Invalid option `record_delimiter`:' ,
5394
+ 'value must be a non empty string or buffer,' ,
5395
+ `got ${ JSON . stringify ( options . record_delimiter ) } `
5396
+ ] , options ) ;
5397
+ }
5391
5398
options . record_delimiter = [ options . record_delimiter ] ;
5399
+ } else if ( ! Array . isArray ( options . record_delimiter ) ) {
5400
+ throw new CsvError ( 'CSV_INVALID_OPTION_RECORD_DELIMITER' , [
5401
+ 'Invalid option `record_delimiter`:' ,
5402
+ 'value must be a string, a buffer or array of string|buffer,' ,
5403
+ `got ${ JSON . stringify ( options . record_delimiter ) } `
5404
+ ] , options ) ;
5392
5405
}
5393
- options . record_delimiter = options . record_delimiter . map ( function ( rd ) {
5406
+ options . record_delimiter = options . record_delimiter . map ( function ( rd , i ) {
5407
+ if ( typeof rd !== 'string' && ! isBuffer ( rd ) ) {
5408
+ throw new CsvError ( 'CSV_INVALID_OPTION_RECORD_DELIMITER' , [
5409
+ 'Invalid option `record_delimiter`:' ,
5410
+ 'value must be a string, a buffer or array of string|buffer' ,
5411
+ `at index ${ i } ,` ,
5412
+ `got ${ JSON . stringify ( rd ) } `
5413
+ ] , options ) ;
5414
+ } else if ( rd . length === 0 ) {
5415
+ throw new CsvError ( 'CSV_INVALID_OPTION_RECORD_DELIMITER' , [
5416
+ 'Invalid option `record_delimiter`:' ,
5417
+ 'value must be a non empty string or buffer' ,
5418
+ `at index ${ i } ,` ,
5419
+ `got ${ JSON . stringify ( rd ) } `
5420
+ ] , options ) ;
5421
+ }
5394
5422
if ( typeof rd === 'string' ) {
5395
5423
rd = Buffer . from ( rd , options . encoding ) ;
5396
5424
}
0 commit comments