@@ -26,6 +26,7 @@ const CLOSE = Symbol('close')
2626const MODE = Symbol ( 'mode' )
2727const warner = require ( './warn-mixin.js' )
2828const winchars = require ( './winchars.js' )
29+ const stripAbsolutePath = require ( './strip-absolute-path.js' )
2930
3031const modeFix = require ( './mode-fix.js' )
3132
@@ -54,12 +55,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
5455 if ( typeof opt . onwarn === 'function' )
5556 this . on ( 'warn' , opt . onwarn )
5657
57- if ( ! this . preservePaths && path . win32 . isAbsolute ( p ) ) {
58- // absolutes on posix are also absolutes on win32
59- // so we only need to test this one to get both
60- const parsed = path . win32 . parse ( p )
61- this . warn ( 'stripping ' + parsed . root + ' from absolute path' , p )
62- this . path = p . substr ( parsed . root . length )
58+ if ( ! this . preservePaths ) {
59+ const s = stripAbsolutePath ( this . path )
60+ if ( s [ 0 ] ) {
61+ this . path = s [ 1 ]
62+ this . warn ( 'stripping ' + s [ 0 ] + ' from absolute path' , p )
63+ }
6364 }
6465
6566 this . win32 = ! ! opt . win32 || process . platform === 'win32'
@@ -343,13 +344,15 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
343344 if ( typeof opt . onwarn === 'function' )
344345 this . on ( 'warn' , opt . onwarn )
345346
346- if ( path . isAbsolute ( this . path ) && ! this . preservePaths ) {
347- const parsed = path . parse ( this . path )
348- this . warn (
349- 'stripping ' + parsed . root + ' from absolute path' ,
350- this . path
351- )
352- this . path = this . path . substr ( parsed . root . length )
347+ if ( ! this . preservePaths ) {
348+ const s = stripAbsolutePath ( this . path )
349+ if ( s [ 0 ] ) {
350+ this . warn (
351+ 'stripping ' + s [ 0 ] + ' from absolute path' ,
352+ this . path
353+ )
354+ this . path = s [ 1 ]
355+ }
353356 }
354357
355358 this . remain = readEntry . size
0 commit comments