This repository was archived by the owner on Jan 14, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ export function parsePatch(uniDiff, options = {}) {
25
25
i ++ ;
26
26
}
27
27
28
+ // Parse file headers if they are defined. Unified diff requires them, but
29
+ // there's no technical issues to have an isolated hunk without file header
28
30
parseFileHeader ( index ) ;
29
31
parseFileHeader ( index ) ;
30
32
@@ -36,7 +38,7 @@ export function parsePatch(uniDiff, options = {}) {
36
38
37
39
if ( / ^ ( I n d e x : | d i f f | \- \- \- | \+ \+ \+ ) \s / . test ( line ) ) {
38
40
break ;
39
- } else if ( / ^ @ @ \s / . test ( line ) ) {
41
+ } else if ( / ^ @ @ / . test ( line ) ) {
40
42
index . hunks . push ( parseHunk ( ) ) ;
41
43
} else if ( line && options . strict ) {
42
44
// Ignore unexpected content unless in strict mode
@@ -50,7 +52,7 @@ export function parsePatch(uniDiff, options = {}) {
50
52
// Parses the --- and +++ headers, if none are found, no lines
51
53
// are consumed.
52
54
function parseFileHeader ( index ) {
53
- let fileHeader = ( / ^ ( \- \- \- | \+ \+ \+ ) \s + ( \S + ) \s ? ( .+ ) / ) . exec ( diffstr [ i ] ) ;
55
+ let fileHeader = ( / ^ ( \- \- \- | \+ \+ \+ ) \s + ( \S + ) \s ? ( .+ ? ) \s * $ / ) . exec ( diffstr [ i ] ) ;
54
56
if ( fileHeader ) {
55
57
let keyPrefix = fileHeader [ 1 ] === '---' ? 'old' : 'new' ;
56
58
index [ keyPrefix + 'FileName' ] = fileHeader [ 2 ] ;
Original file line number Diff line number Diff line change @@ -554,5 +554,36 @@ describe('patch/apply', function() {
554
554
}
555
555
} ) ;
556
556
} ) ;
557
+ it ( 'should handle patches without Index' , function ( done ) {
558
+ const patch =
559
+ '===================================================================\n'
560
+ + '--- test\theader1\n'
561
+ + '+++ test\theader2\n'
562
+ + '@@ -1,3 +1,4 @@\n'
563
+ + ' line2\n'
564
+ + ' line3\n'
565
+ + '+line4\n'
566
+ + ' line5\n'
567
+ + '===================================================================\n'
568
+ + '--- test2\theader1\n'
569
+ + '+++ test2\theader2\n'
570
+ + '@@ -1,3 +1,4 @@\n'
571
+ + ' foo2\n'
572
+ + ' foo3\n'
573
+ + '+foo4\n'
574
+ + ' foo5\n' ;
575
+
576
+ applyPatches ( patch , {
577
+ loadFile ( index , callback ) {
578
+ callback ( undefined , contents [ index . oldFileName ] ) ;
579
+ } ,
580
+ patched ( index , content ) {
581
+ expect ( content )
582
+ . to . equal ( expected [ index . newFileName ] )
583
+ . to . not . be . undefined ;
584
+ } ,
585
+ complete : done
586
+ } ) ;
587
+ } ) ;
557
588
} ) ;
558
589
} ) ;
You can’t perform that action at this time.
0 commit comments