@@ -260,6 +260,7 @@ Each file requires its own path, start_line, and diff elements.
260260 const state = { current : State . START , line : 0 }
261261
262262 const SEARCH = "<<<<<<< SEARCH"
263+ const SEARCH_PATTERN = / ^ < < < < < < < S E A R C H > ? $ /
263264 const SEP = "======="
264265 const REPLACE = ">>>>>>> REPLACE"
265266 const SEARCH_PREFIX = "<<<<<<< "
@@ -329,7 +330,7 @@ Each file requires its own path, start_line, and diff elements.
329330 } )
330331
331332 const lines = diffContent . split ( "\n" )
332- const searchCount = lines . filter ( ( l ) => l . trim ( ) === SEARCH ) . length
333+ const searchCount = lines . filter ( ( l ) => SEARCH_PATTERN . test ( l . trim ( ) ) ) . length
333334 const sepCount = lines . filter ( ( l ) => l . trim ( ) === SEP ) . length
334335 const replaceCount = lines . filter ( ( l ) => l . trim ( ) === REPLACE ) . length
335336
@@ -357,20 +358,20 @@ Each file requires its own path, start_line, and diff elements.
357358 : reportMergeConflictError ( SEP , SEARCH )
358359 if ( marker === REPLACE ) return reportInvalidDiffError ( REPLACE , SEARCH )
359360 if ( marker . startsWith ( REPLACE_PREFIX ) ) return reportMergeConflictError ( marker , SEARCH )
360- if ( marker === SEARCH ) state . current = State . AFTER_SEARCH
361+ if ( SEARCH_PATTERN . test ( marker ) ) state . current = State . AFTER_SEARCH
361362 else if ( marker . startsWith ( SEARCH_PREFIX ) ) return reportMergeConflictError ( marker , SEARCH )
362363 break
363364
364365 case State . AFTER_SEARCH :
365- if ( marker === SEARCH ) return reportInvalidDiffError ( SEARCH , SEP )
366+ if ( SEARCH_PATTERN . test ( marker ) ) return reportInvalidDiffError ( SEARCH , SEP )
366367 if ( marker . startsWith ( SEARCH_PREFIX ) ) return reportMergeConflictError ( marker , SEARCH )
367368 if ( marker === REPLACE ) return reportInvalidDiffError ( REPLACE , SEP )
368369 if ( marker . startsWith ( REPLACE_PREFIX ) ) return reportMergeConflictError ( marker , SEARCH )
369370 if ( marker === SEP ) state . current = State . AFTER_SEPARATOR
370371 break
371372
372373 case State . AFTER_SEPARATOR :
373- if ( marker === SEARCH ) return reportInvalidDiffError ( SEARCH , REPLACE )
374+ if ( SEARCH_PATTERN . test ( marker ) ) return reportInvalidDiffError ( SEARCH , REPLACE )
374375 if ( marker . startsWith ( SEARCH_PREFIX ) ) return reportMergeConflictError ( marker , REPLACE )
375376 if ( marker === SEP )
376377 return likelyBadStructure
@@ -467,7 +468,7 @@ Each file requires its own path, start_line, and diff elements.
467468 */
468469 let matches = [
469470 ...diffContent . matchAll (
470- / (?: ^ | \n ) (?< ! \\ ) < < < < < < < S E A R C H \s * \n ( (?: \: s t a r t _ l i n e : \s * ( \d + ) \s * \n ) ) ? ( (?: \: e n d _ l i n e : \s * ( \d + ) \s * \n ) ) ? ( (?< ! \\ ) - - - - - - - \s * \n ) ? ( [ \s \S ] * ?) (?: \n ) ? (?: (?< = \n ) (?< ! \\ ) = = = = = = = \s * \n ) ( [ \s \S ] * ?) (?: \n ) ? (?: (?< = \n ) (?< ! \\ ) > > > > > > > R E P L A C E ) (? = \n | $ ) / g,
471+ / (?: ^ | \n ) (?< ! \\ ) < < < < < < < S E A R C H > ? \s * \n ( (?: \: s t a r t _ l i n e : \s * ( \d + ) \s * \n ) ) ? ( (?: \: e n d _ l i n e : \s * ( \d + ) \s * \n ) ) ? ( (?< ! \\ ) - - - - - - - \s * \n ) ? ( [ \s \S ] * ?) (?: \n ) ? (?: (?< = \n ) (?< ! \\ ) = = = = = = = \s * \n ) ( [ \s \S ] * ?) (?: \n ) ? (?: (?< = \n ) (?< ! \\ ) > > > > > > > R E P L A C E ) (? = \n | $ ) / g,
471472 ) ,
472473 ]
473474
0 commit comments