File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,7 +57,11 @@ export function parsePatch(uniDiff, options = {}) {
5757 const fileHeader = headerPattern . exec ( diffstr [ i ] ) ;
5858 if ( fileHeader ) {
5959 let keyPrefix = fileHeader [ 1 ] === '---' ? 'old' : 'new' ;
60- index [ keyPrefix + 'FileName' ] = fileHeader [ 2 ] ;
60+ let fileName = fileHeader [ 2 ] . replace ( / \\ \\ / g, '\\' ) ;
61+ if ( fileName . startsWith ( '"' ) && fileName . endsWith ( '"' ) ) {
62+ fileName = fileName . substr ( 1 , fileName . length - 2 ) ;
63+ }
64+ index [ keyPrefix + 'FileName' ] = fileName ;
6165 index [ keyPrefix + 'Header' ] = fileHeader [ 3 ] ;
6266
6367 i ++ ;
Original file line number Diff line number Diff line change @@ -276,6 +276,44 @@ Index: test2
276276 } ] ) ;
277277 } ) ;
278278
279+ it ( 'should parse patches with filenames having quotes and back slashes' , function ( ) {
280+ expect ( parsePatch (
281+ `Index: test
282+ ===================================================================
283+ --- "from\\\\a\\\\file\\\\with\\\\quotes\\\\and\\\\backslash"\theader1
284+ +++ "to\\\\a\\\\file\\\\with\\\\quotes\\\\and\\\\backslash"\theader2
285+ @@ -1,3 +1,4 @@
286+ line2
287+ line3
288+ +line4
289+ line5` ) )
290+ . to . eql ( [ {
291+ index : 'test' ,
292+ oldFileName : 'from\\a\\file\\with\\quotes\\and\\backslash' ,
293+ oldHeader : 'header1' ,
294+ newFileName : 'to\\a\\file\\with\\quotes\\and\\backslash' ,
295+ newHeader : 'header2' ,
296+ hunks : [
297+ {
298+ oldStart : 1 , oldLines : 3 ,
299+ newStart : 1 , newLines : 4 ,
300+ lines : [
301+ ' line2' ,
302+ ' line3' ,
303+ '+line4' ,
304+ ' line5'
305+ ] ,
306+ linedelimiters : [
307+ '\n' ,
308+ '\n' ,
309+ '\n' ,
310+ '\n'
311+ ]
312+ }
313+ ]
314+ } ] ) ;
315+ } ) ;
316+
279317 it ( 'should note added EOFNL' , function ( ) {
280318 expect ( parsePatch (
281319`@@ -1,3 +1,4 @@
You can’t perform that action at this time.
0 commit comments