@@ -5,7 +5,7 @@ import { excelBOM } from './constants';
55import type { Csv2JsonParams , FullCsv2JsonOptions , HeaderField } from './types' ;
66import * as utils from './utils' ;
77
8- export const Csv2Json = function ( options : FullCsv2JsonOptions ) {
8+ export const Csv2Json = function ( options : FullCsv2JsonOptions ) {
99 const escapedWrapDelimiterRegex = new RegExp ( options . delimiter . wrap + options . delimiter . wrap , 'g' ) ,
1010 excelBOMRegex = new RegExp ( '^' + excelBOM ) ,
1111 valueParserFn = options . parseValue && typeof options . parseValue === 'function' ? options . parseValue : JSON . parse ;
@@ -166,9 +166,18 @@ export const Csv2Json = function(options: FullCsv2JsonOptions) {
166166 if ( utils . getNCharacters ( csv , index + 1 , eolDelimiterLength ) === options . delimiter . eol ) {
167167 index += options . delimiter . eol . length + 1 ; // Skip past EOL
168168 }
169- }
170-
171- else if ( ( charBefore !== options . delimiter . wrap || stateVariables . justParsedDoubleQuote && charBefore === options . delimiter . wrap ) &&
169+ } else if ( charBefore === options . delimiter . field && character === options . delimiter . wrap && charAfter === options . delimiter . eol ) {
170+ // We reached the start of a wrapped new field that begins with an EOL delimiter
171+
172+ // Retrieve the remaining value and add it to the split line list of values
173+ splitLine . push ( csv . substring ( stateVariables . startIndex , index - 1 ) ) ;
174+
175+ stateVariables . startIndex = index ;
176+ stateVariables . parsingValue = true ;
177+ stateVariables . insideWrapDelimiter = true ;
178+ stateVariables . justParsedDoubleQuote = true ;
179+ index += 1 ;
180+ } else if ( ( charBefore !== options . delimiter . wrap || stateVariables . justParsedDoubleQuote && charBefore === options . delimiter . wrap ) &&
172181 character === options . delimiter . wrap && utils . getNCharacters ( csv , index + 1 , eolDelimiterLength ) === options . delimiter . eol ) {
173182 // If we reach a wrap which is not preceded by a wrap delim and the next character is an EOL delim (ie. *"\n)
174183
0 commit comments