File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,8 @@ class Unpack extends Parser {
205
205
if ( parts . length < this . strip )
206
206
return false
207
207
entry . path = parts . slice ( this . strip ) . join ( '/' )
208
+ if ( entry . path === '' && entry . type !== 'Directory' && entry . type !== 'GNUDumpDir' )
209
+ return false
208
210
209
211
if ( entry . type === 'Link' ) {
210
212
const linkparts = entry . linkpath . split ( / \/ | \\ / )
Original file line number Diff line number Diff line change @@ -2658,3 +2658,46 @@ t.test('drop entry from dirCache if no longer a directory', t => {
2658
2658
check ( t , path )
2659
2659
} )
2660
2660
} )
2661
+
2662
+ t . test ( 'using strip option when top level file exists' , t => {
2663
+ const dir = path . resolve ( unpackdir , 'strip-with-top-file' )
2664
+ mkdirp . sync ( dir + '/sync/y' )
2665
+ mkdirp . sync ( dir + '/async/y' )
2666
+ const data = makeTar ( [
2667
+ {
2668
+ path : 'top' ,
2669
+ type : 'File' ,
2670
+ size : 0 ,
2671
+ } ,
2672
+ {
2673
+ path : 'x' ,
2674
+ type : 'Directory' ,
2675
+ } ,
2676
+ {
2677
+ path : 'x/a' ,
2678
+ type : 'File' ,
2679
+ size : 'a' . length ,
2680
+ } ,
2681
+ 'a' ,
2682
+ '' ,
2683
+ '' ,
2684
+ ] )
2685
+ t . plan ( 2 )
2686
+ const check = ( t , path ) => {
2687
+ t . equal ( fs . statSync ( path ) . isDirectory ( ) , true )
2688
+ t . equal ( fs . lstatSync ( path + '/a' ) . isFile ( ) , true )
2689
+ t . throws ( ( ) => fs . statSync ( path + '/top' ) , { code : 'ENOENT' } )
2690
+ t . end ( )
2691
+ }
2692
+ t . test ( 'async' , t => {
2693
+ const path = dir + '/async'
2694
+ new Unpack ( { cwd : path , strip : 1 } )
2695
+ . on ( 'end' , ( ) => check ( t , path ) )
2696
+ . end ( data )
2697
+ } )
2698
+ t . test ( 'sync' , t => {
2699
+ const path = dir + '/sync'
2700
+ new UnpackSync ( { cwd : path , strip : 1 } ) . end ( data )
2701
+ check ( t , path )
2702
+ } )
2703
+ } )
You can’t perform that action at this time.
0 commit comments