File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ async function pack (spec = 'file:.', opts = {}) {
3737 // check for explicit `false` so the default behavior is to skip writing to disk
3838 if ( opts . dryRun === false ) {
3939 const filename = `${ manifest . name } -${ manifest . version } .tgz`
40- . replace ( / ^ @ / , '' ) . replace ( / \/ / , '-' )
40+ . replace ( / ^ @ / , '' ) . replace ( / [ / \\ ] / g , '-' )
4141 const destination = path . resolve ( opts . packDestination , filename )
4242 await writeFile ( destination , tarball )
4343 }
Original file line number Diff line number Diff line change @@ -36,6 +36,29 @@ t.test('packs from local directory', async t => {
3636 } )
3737} )
3838
39+ t . test ( 'flattens path separators in name so tarball stays in packDestination' , async t => {
40+ const testDir = t . testdir ( {
41+ src : {
42+ 'package.json' : JSON . stringify ( {
43+ name : 'x/../../../../../../escaped' ,
44+ version : '1.0.0' ,
45+ } , null , 2 ) ,
46+ } ,
47+ dest : { } ,
48+ } )
49+
50+ const dest = path . join ( testDir , 'dest' )
51+ await pack ( `file:${ path . join ( testDir , 'src' ) } ` , {
52+ dryRun : false ,
53+ packDestination : dest ,
54+ silent : true ,
55+ } )
56+
57+ const written = fs . readdirSync ( dest )
58+ t . same ( written , [ 'x-..-..-..-..-..-..-escaped-1.0.0.tgz' ] , 'separators flattened to a single filename' )
59+ t . notOk ( fs . existsSync ( path . join ( testDir , 'escaped-1.0.0.tgz' ) ) , 'nothing escaped the destination' )
60+ } )
61+
3962t . test ( 'writes tarball to file when dryRun === false' , async t => {
4063 const testDir = t . testdir ( {
4164 'package.json' : JSON . stringify ( {
You can’t perform that action at this time.
0 commit comments