File tree 3 files changed +59
-1
lines changed
3 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 33
33
"babel-preset-es2015-mod" : " ^6.3.13" ,
34
34
"chai" : " ^3.3.0" ,
35
35
"colors" : " ^1.1.2" ,
36
+ "deindent" : " ^0.1.0" ,
36
37
"eslint" : " ^1.6.0" ,
37
38
"grunt" : " ^0.4.5" ,
38
39
"grunt-babel" : " ^6.0.0" ,
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ export function parsePatch(uniDiff, options = {}) {
52
52
// Parses the --- and +++ headers, if none are found, no lines
53
53
// are consumed.
54
54
function parseFileHeader ( index ) {
55
- let fileHeader = ( / ^ ( \- \- \- | \+ \+ \+ ) \s + ( \S * ) \s ? ( .* ?) \s * $ / ) . exec ( diffstr [ i ] ) ;
55
+ const headerPattern = / ^ ( - - - | \+ \+ \+ ) \s + ( [ \S ] * ) (?: \t ( .* ?) \s * ) ? $ / ;
56
+ const fileHeader = headerPattern . exec ( diffstr [ i ] ) ;
56
57
if ( fileHeader ) {
57
58
let keyPrefix = fileHeader [ 1 ] === '---' ? 'old' : 'new' ;
58
59
index [ keyPrefix + 'FileName' ] = fileHeader [ 2 ] ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import {parsePatch} from '../../lib/patch/parse';
3
3
import { createPatch } from '../../lib/patch/create' ;
4
4
5
5
import { expect } from 'chai' ;
6
+ import deindent from 'deindent' ;
6
7
7
8
describe ( 'patch/apply' , function ( ) {
8
9
describe ( '#applyPatch' , function ( ) {
@@ -602,5 +603,60 @@ describe('patch/apply', function() {
602
603
complete : done
603
604
} ) ;
604
605
} ) ;
606
+
607
+ it ( 'should handle file names containing spaces' , done => {
608
+ const patch = deindent
609
+ `===================================================================
610
+ --- test file\theader1
611
+ +++ test file\theader2
612
+ @@ -1,2 +1,3 @@
613
+ line1
614
+ +line2
615
+ line3
616
+ ===================================================================
617
+ --- test file 2\theader1
618
+ +++ test file 2\theader2
619
+ @@ -1,2 +1,3 @@
620
+ foo1
621
+ +foo2
622
+ foo3
623
+ ` ;
624
+
625
+ const contents = {
626
+ 'test file' : deindent
627
+ `line1
628
+ line3
629
+ ` ,
630
+ 'test file 2' : deindent
631
+ `foo1
632
+ foo3
633
+ `
634
+ } ;
635
+
636
+ const expected = {
637
+ 'test file' : deindent
638
+ `line1
639
+ line2
640
+ line3
641
+ ` ,
642
+ 'test file 2' : deindent
643
+ `foo1
644
+ foo2
645
+ foo3
646
+ `
647
+ } ;
648
+
649
+ applyPatches ( patch , {
650
+ loadFile ( index , callback ) {
651
+ callback ( undefined , contents [ index . oldFileName ] ) ;
652
+ } ,
653
+ patched ( index , content ) {
654
+ expect ( content )
655
+ . to . equal ( expected [ index . newFileName ] )
656
+ . to . not . be . undefined ;
657
+ } ,
658
+ complete : done
659
+ } ) ;
660
+ } ) ;
605
661
} ) ;
606
662
} ) ;
You can’t perform that action at this time.
0 commit comments