csv-parse
Advanced tools
Comparing version 5.3.0 to 5.3.1
@@ -43,3 +43,3 @@ | ||
if(end) return false; | ||
const {quote} = this.options; | ||
const {encoding, escape, quote} = this.options; | ||
const {quoting, needMoreDataSize, recordDelimiterMaxLength} = this.state; | ||
@@ -50,5 +50,11 @@ const numOfCharLeft = bufLen - i - 1; | ||
// Skip if the remaining buffer smaller than record delimiter | ||
recordDelimiterMaxLength, | ||
// Skip if the remaining buffer can be record delimiter following the closing quote | ||
// 1 is for quote.length | ||
// If "record_delimiter" is yet to be discovered: | ||
// 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0` | ||
// 2. We set the length to windows line ending in the current encoding | ||
// Note, that encoding is known from user or bom discovery at that point | ||
// recordDelimiterMaxLength, | ||
recordDelimiterMaxLength === 0 ? Buffer.from('\r\n', encoding).length : recordDelimiterMaxLength, | ||
// Skip if remaining buffer can be an escaped quote | ||
quoting ? ((escape === null ? 0 : escape.length) + quote.length) : 0, | ||
// Skip if remaining buffer can be record delimiter following the closing quote | ||
quoting ? (quote.length + recordDelimiterMaxLength) : 0, | ||
@@ -649,18 +655,22 @@ ); | ||
__autoDiscoverRecordDelimiter: function(buf, pos){ | ||
const {encoding} = this.options; | ||
const chr = buf[pos]; | ||
if(chr === cr){ | ||
if(buf[pos+1] === nl){ | ||
this.options.record_delimiter.push(Buffer.from('\r\n', encoding)); | ||
this.state.recordDelimiterMaxLength = 2; | ||
return 2; | ||
}else{ | ||
this.options.record_delimiter.push(Buffer.from('\r', encoding)); | ||
this.state.recordDelimiterMaxLength = 1; | ||
return 1; | ||
const { encoding } = this.options; | ||
// Note, we don't need to cache this information in state, | ||
// It is only called on the first line until we find out a suitable | ||
// record delimiter. | ||
const rds = [ | ||
// Important, the windows line ending must be before mac os 9 | ||
Buffer.from('\r\n', encoding), | ||
Buffer.from('\n', encoding), | ||
Buffer.from('\r', encoding), | ||
]; | ||
loop: for(let i = 0; i < rds.length; i++){ | ||
const l = rds[i].length; | ||
for(let j = 0; j < l; j++){ | ||
if(rds[i][j] !== buf[pos + j]){ | ||
continue loop; | ||
} | ||
} | ||
}else if(chr === nl){ | ||
this.options.record_delimiter.push(Buffer.from('\n', encoding)); | ||
this.state.recordDelimiterMaxLength = 1; | ||
return 1; | ||
this.options.record_delimiter.push(rds[i]); | ||
this.state.recordDelimiterMaxLength = rds[i].length; | ||
return rds[i].length; | ||
} | ||
@@ -667,0 +677,0 @@ return 0; |
@@ -44,3 +44,3 @@ | ||
record_length: 0, | ||
recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 2 : Math.max(...options.record_delimiter.map((v) => v.length)), | ||
recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 0 : Math.max(...options.record_delimiter.map((v) => v.length)), | ||
trimChars: [Buffer.from(' ', options.encoding)[0], Buffer.from('\t', options.encoding)[0]], | ||
@@ -47,0 +47,0 @@ wasQuoting: false, |
{ | ||
"version": "5.3.0", | ||
"version": "5.3.1", | ||
"name": "csv-parse", | ||
@@ -127,3 +127,3 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API", | ||
}, | ||
"gitHead": "c6745735a41521aa6b9876b0a38dbf2adebb15f2" | ||
"gitHead": "dbe9cb5bd4ece5148d44be795d3866fab119f74f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1321523
31010