csv-parse
Advanced tools
Comparing version 2.3.0 to 2.4.0
# Changelog | ||
## Version 2.4.0 | ||
* trim: after and before quote | ||
* tests: compatibility with Node.js 10 | ||
* trim: handle quote followed by escape | ||
* parser: set nextChar to null instead of empty | ||
* travis: run against node 8 and 10 | ||
## Version 2.3.0 | ||
cast: pass the header property | ||
auto_parse: deprecated message on tests | ||
cast: inject lines property | ||
* cast: pass the header property | ||
* auto_parse: deprecated message on tests | ||
* cast: inject lines property | ||
@@ -10,0 +18,0 @@ ## Version 2.2.0 |
@@ -399,3 +399,3 @@ 'use strict'; | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isNextCharTrimable, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, ref6, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
is_int = function is_int(value) { | ||
@@ -480,3 +480,3 @@ if (typeof _this2.is_int === 'function') { | ||
char = this._.nextChar ? this._.nextChar : chars.charAt(i); | ||
this._.nextChar = l > i + 1 ? chars.charAt(i + 1) : ''; | ||
this._.nextChar = l > i + 1 ? chars.charAt(i + 1) : null; | ||
if (this.options.raw) { | ||
@@ -515,3 +515,3 @@ this._.rawBuf += char; | ||
isQuote = this._.nextChar === this.options.quote; | ||
if (!(escapeIsQuote && this._.field == null && !this._.quoting) && (isEscape || isQuote)) { | ||
if (!(escapeIsQuote && !this._.field && !this._.quoting) && (isEscape || isQuote)) { | ||
i++; | ||
@@ -532,3 +532,7 @@ char = this._.nextChar; | ||
} | ||
// Char match quote | ||
if (!this._.commenting && char === this.options.quote) { | ||
if (this._.acceptOnlyEmptyChars && char !== ' ' && char !== '\t') { | ||
return this.error('Only trimable characters are accepted after quotes'); | ||
} | ||
if (this._.quoting) { | ||
@@ -541,2 +545,3 @@ // Make sure a closing quote is followed by a delimiter | ||
// Otherwise, if this is not "relax" mode, throw an error | ||
isNextCharTrimable = rtrim && ((ref1 = this._.nextChar) === ' ' || ref1 === '\t'); | ||
areNextCharsRowDelimiters = this.options.rowDelimiter && this.options.rowDelimiter.some(function (rd) { | ||
@@ -547,3 +552,3 @@ return chars.substr(i + 1, rd.length) === rd; | ||
isNextCharAComment = this._.nextChar === this.options.comment; | ||
if (this._.nextChar && !areNextCharsRowDelimiters && !areNextCharsDelimiter && !isNextCharAComment) { | ||
if (this._.nextChar != null && !isNextCharTrimable && !areNextCharsRowDelimiters && !areNextCharsDelimiter && !isNextCharAComment) { | ||
if (this.options.relax) { | ||
@@ -559,2 +564,8 @@ this._.quoting = false; | ||
} | ||
} else if (this._.nextChar != null && isNextCharTrimable) { | ||
i++; | ||
this._.quoting = false; | ||
this._.closingQuote = this.options.quote.length; | ||
this._.acceptOnlyEmptyChars = true; | ||
continue; | ||
} else { | ||
@@ -596,2 +607,14 @@ i++; | ||
isDelimiter = chars.substr(i, this.options.delimiter.length) === this.options.delimiter; | ||
if (this._.acceptOnlyEmptyChars) { | ||
if (isDelimiter || isRowDelimiter) { | ||
this._.acceptOnlyEmptyChars = false; | ||
} else { | ||
if (char === ' ' || char === '\t') { | ||
i++; | ||
continue; | ||
} else { | ||
return this.error('Only trimable characters are accepted after quotes'); | ||
} | ||
} | ||
} | ||
if (!this._.commenting && !this._.quoting && (isDelimiter || isRowDelimiter)) { | ||
@@ -613,3 +636,3 @@ if (isRowDelimiter) { | ||
if (!this._.closingQuote) { | ||
this._.field = (ref1 = this._.field) != null ? ref1.trimRight() : void 0; | ||
this._.field = (ref2 = this._.field) != null ? ref2.trimRight() : void 0; | ||
} | ||
@@ -664,6 +687,6 @@ } | ||
} | ||
if (!this._.commenting && ((ref2 = this._.field) != null ? ref2.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (!this._.commenting && ((ref3 = this._.field) != null ? ref3.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error('Field exceeds max_limit_on_data_read setting (' + this.options.max_limit_on_data_read + ') ' + JSON.stringify(this.options.delimiter)); | ||
} | ||
if (!this._.commenting && ((ref3 = this._.line) != null ? ref3.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (!this._.commenting && ((ref4 = this._.line) != null ? ref4.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error('Row delimiter not found in the file ' + JSON.stringify(this.options.rowDelimiter)); | ||
@@ -680,3 +703,3 @@ } | ||
if (!this._.closingQuote) { | ||
this._.field = (ref4 = this._.field) != null ? ref4.trimRight() : void 0; | ||
this._.field = (ref5 = this._.field) != null ? ref5.trimRight() : void 0; | ||
} | ||
@@ -687,3 +710,3 @@ } | ||
} | ||
if (((ref5 = this._.field) != null ? ref5.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (((ref6 = this._.field) != null ? ref6.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error('Delimiter not found in the file ' + JSON.stringify(this.options.delimiter)); | ||
@@ -690,0 +713,0 @@ } |
@@ -378,3 +378,3 @@ // Generated by CoffeeScript 2.2.4 | ||
Parser.prototype.__write = function(chars, end) { | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isNextCharTrimable, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, ref6, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
is_int = (value) => { | ||
@@ -457,3 +457,3 @@ if (typeof this.is_int === 'function') { | ||
char = this._.nextChar ? this._.nextChar : chars.charAt(i); | ||
this._.nextChar = l > i + 1 ? chars.charAt(i + 1) : ''; | ||
this._.nextChar = l > i + 1 ? chars.charAt(i + 1) : null; | ||
if (this.options.raw) { | ||
@@ -492,3 +492,3 @@ this._.rawBuf += char; | ||
isQuote = this._.nextChar === this.options.quote; | ||
if (!(escapeIsQuote && (this._.field == null) && !this._.quoting) && (isEscape || isQuote)) { | ||
if (!(escapeIsQuote && !this._.field && !this._.quoting) && (isEscape || isQuote)) { | ||
i++; | ||
@@ -509,3 +509,7 @@ char = this._.nextChar; | ||
} | ||
// Char match quote | ||
if (!this._.commenting && char === this.options.quote) { | ||
if (this._.acceptOnlyEmptyChars && (char !== ' ' && char !== '\t')) { | ||
return this.error('Only trimable characters are accepted after quotes'); | ||
} | ||
if (this._.quoting) { | ||
@@ -518,2 +522,3 @@ // Make sure a closing quote is followed by a delimiter | ||
// Otherwise, if this is not "relax" mode, throw an error | ||
isNextCharTrimable = rtrim && ((ref1 = this._.nextChar) === ' ' || ref1 === '\t'); | ||
areNextCharsRowDelimiters = this.options.rowDelimiter && this.options.rowDelimiter.some(function(rd) { | ||
@@ -524,3 +529,3 @@ return chars.substr(i + 1, rd.length) === rd; | ||
isNextCharAComment = this._.nextChar === this.options.comment; | ||
if (this._.nextChar && !areNextCharsRowDelimiters && !areNextCharsDelimiter && !isNextCharAComment) { | ||
if ((this._.nextChar != null) && !isNextCharTrimable && !areNextCharsRowDelimiters && !areNextCharsDelimiter && !isNextCharAComment) { | ||
if (this.options.relax) { | ||
@@ -536,2 +541,8 @@ this._.quoting = false; | ||
} | ||
} else if ((this._.nextChar != null) && isNextCharTrimable) { | ||
i++; | ||
this._.quoting = false; | ||
this._.closingQuote = this.options.quote.length; | ||
this._.acceptOnlyEmptyChars = true; | ||
continue; | ||
} else { | ||
@@ -573,2 +584,14 @@ i++; | ||
isDelimiter = chars.substr(i, this.options.delimiter.length) === this.options.delimiter; | ||
if (this._.acceptOnlyEmptyChars) { | ||
if (isDelimiter || isRowDelimiter) { | ||
this._.acceptOnlyEmptyChars = false; | ||
} else { | ||
if (char === ' ' || char === '\t') { | ||
i++; | ||
continue; | ||
} else { | ||
return this.error('Only trimable characters are accepted after quotes'); | ||
} | ||
} | ||
} | ||
if (!this._.commenting && !this._.quoting && (isDelimiter || isRowDelimiter)) { | ||
@@ -590,3 +613,3 @@ if (isRowDelimiter) { | ||
if (!this._.closingQuote) { | ||
this._.field = (ref1 = this._.field) != null ? ref1.trimRight() : void 0; | ||
this._.field = (ref2 = this._.field) != null ? ref2.trimRight() : void 0; | ||
} | ||
@@ -639,6 +662,6 @@ } | ||
} | ||
if (!this._.commenting && ((ref2 = this._.field) != null ? ref2.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (!this._.commenting && ((ref3 = this._.field) != null ? ref3.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error(`Field exceeds max_limit_on_data_read setting (${this.options.max_limit_on_data_read}) ${JSON.stringify(this.options.delimiter)}`); | ||
} | ||
if (!this._.commenting && ((ref3 = this._.line) != null ? ref3.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (!this._.commenting && ((ref4 = this._.line) != null ? ref4.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error(`Row delimiter not found in the file ${JSON.stringify(this.options.rowDelimiter)}`); | ||
@@ -655,3 +678,3 @@ } | ||
if (!this._.closingQuote) { | ||
this._.field = (ref4 = this._.field) != null ? ref4.trimRight() : void 0; | ||
this._.field = (ref5 = this._.field) != null ? ref5.trimRight() : void 0; | ||
} | ||
@@ -662,3 +685,3 @@ } | ||
} | ||
if (((ref5 = this._.field) != null ? ref5.length : void 0) > this.options.max_limit_on_data_read) { | ||
if (((ref6 = this._.field) != null ? ref6.length : void 0) > this.options.max_limit_on_data_read) { | ||
return Error(`Delimiter not found in the file ${JSON.stringify(this.options.delimiter)}`); | ||
@@ -665,0 +688,0 @@ } |
{ | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"name": "csv-parse", | ||
@@ -4,0 +4,0 @@ "description": "CSV parsing implementing the Node.js `stream.Transform` API", |
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
70348
1698