File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 458
458
applyPatch : function ( oldStr , uniDiff ) {
459
459
var diffstr = uniDiff . split ( '\n' ) ;
460
460
var diff = [ ] ;
461
- var remEOFNL = false ,
461
+ var i = 0 ,
462
+ remEOFNL = false ,
462
463
addEOFNL = false ;
463
464
464
- for ( var i = ( diffstr [ 0 ] [ 0 ] === 'I' ?4 :0 ) ; i < diffstr . length ; i ++ ) {
465
+ // Skip to the first change chunk
466
+ while ( i < diffstr . length && ! / ^ @ @ / . test ( diffstr [ i ] ) ) {
467
+ i ++ ;
468
+ }
469
+
470
+ for ( ; i < diffstr . length ; i ++ ) {
465
471
if ( diffstr [ i ] [ 0 ] === '@' ) {
466
472
var meh = diffstr [ i ] . split ( / @ @ - ( \d + ) , ( \d + ) \+ ( \d + ) , ( \d + ) @ @ / ) ;
467
473
diff . unshift ( {
Original file line number Diff line number Diff line change @@ -269,4 +269,24 @@ describe('#applyPatch', function() {
269
269
+ '+++ testFileName\tNew Header\n' ;
270
270
diff . applyPatch ( oldFile , diffFile ) . should . equal ( oldFile ) ;
271
271
} ) ;
272
+
273
+ it ( 'should apply patches that lack an index header' , function ( ) {
274
+ diff . applyPatch (
275
+ 'line2\n' +
276
+ 'line3\n' +
277
+ 'line5\n' ,
278
+
279
+ '--- test\theader1\n'
280
+ + '+++ test\theader2\n'
281
+ + '@@ -1,3 +1,4 @@\n'
282
+ + ' line2\n'
283
+ + ' line3\n'
284
+ + '+line4\n'
285
+ + ' line5\n' )
286
+ . should . equal (
287
+ 'line2\n'
288
+ + 'line3\n'
289
+ + 'line4\n'
290
+ + 'line5\n' ) ;
291
+ } ) ;
272
292
} ) ;
You can’t perform that action at this time.
0 commit comments