@@ -5,7 +5,7 @@ import { excelBOM } from './constants';
5
5
import type { Csv2JsonParams , FullCsv2JsonOptions , HeaderField } from './types' ;
6
6
import * as utils from './utils' ;
7
7
8
- export const Csv2Json = function ( options : FullCsv2JsonOptions ) {
8
+ export const Csv2Json = function ( options : FullCsv2JsonOptions ) {
9
9
const escapedWrapDelimiterRegex = new RegExp ( options . delimiter . wrap + options . delimiter . wrap , 'g' ) ,
10
10
excelBOMRegex = new RegExp ( '^' + excelBOM ) ,
11
11
valueParserFn = options . parseValue && typeof options . parseValue === 'function' ? options . parseValue : JSON . parse ;
@@ -166,9 +166,18 @@ export const Csv2Json = function(options: FullCsv2JsonOptions) {
166
166
if ( utils . getNCharacters ( csv , index + 1 , eolDelimiterLength ) === options . delimiter . eol ) {
167
167
index += options . delimiter . eol . length + 1 ; // Skip past EOL
168
168
}
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 ) &&
172
181
character === options . delimiter . wrap && utils . getNCharacters ( csv , index + 1 , eolDelimiterLength ) === options . delimiter . eol ) {
173
182
// If we reach a wrap which is not preceded by a wrap delim and the next character is an EOL delim (ie. *"\n)
174
183
0 commit comments