diff --git a/node_modules/tar/lib/strip-absolute-path.js b/node_modules/tar/lib/strip-absolute-path.js new file mode 100644 index 0000000000000..49161ddc30473 --- /dev/null +++ b/node_modules/tar/lib/strip-absolute-path.js @@ -0,0 +1,14 @@ +// unix absolute paths are also absolute on win32, so we use this for both +const { isAbsolute, parse } = require('path').win32 + +// returns [root, stripped] +module.exports = path => { + let r = '' + while (isAbsolute(path)) { + // windows will think that //x/y/z has a "root" of //x/y/ + const root = path.charAt(0) === '/' ? '/' : parse(path).root + path = path.substr(root.length) + r += root + } + return [r, path] +} diff --git a/node_modules/tar/lib/unpack.js b/node_modules/tar/lib/unpack.js index 7d4b79d9eb3f0..216fa71bd6a48 100644 --- a/node_modules/tar/lib/unpack.js +++ b/node_modules/tar/lib/unpack.js @@ -14,6 +14,7 @@ const path = require('path') const mkdir = require('./mkdir.js') const wc = require('./winchars.js') const pathReservations = require('./path-reservations.js') +const stripAbsolutePath = require('./strip-absolute-path.js') const ONENTRY = Symbol('onEntry') const CHECKFS = Symbol('checkFs') @@ -224,11 +225,10 @@ class Unpack extends Parser { // absolutes on posix are also absolutes on win32 // so we only need to test this one to get both - if (path.win32.isAbsolute(p)) { - const parsed = path.win32.parse(p) - entry.path = p.substr(parsed.root.length) - const r = parsed.root - this.warn('TAR_ENTRY_INFO', `stripping ${r} from absolute path`, { + const [root, stripped] = stripAbsolutePath(p) + if (root) { + entry.path = stripped + this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute path`, { entry, path: p, }) diff --git a/node_modules/tar/lib/write-entry.js b/node_modules/tar/lib/write-entry.js index 1d0b746cd6818..0301759ad386f 100644 --- a/node_modules/tar/lib/write-entry.js +++ b/node_modules/tar/lib/write-entry.js @@ -23,6 +23,7 @@ const CLOSE = Symbol('close') const MODE = Symbol('mode') const warner = require('./warn-mixin.js') const winchars = require('./winchars.js') +const stripAbsolutePath = require('./strip-absolute-path.js') const modeFix = require('./mode-fix.js') @@ -52,12 +53,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass { this.on('warn', opt.onwarn) let pathWarn = false - if (!this.preservePaths && path.win32.isAbsolute(p)) { - // absolutes on posix are also absolutes on win32 - // so we only need to test this one to get both - const parsed = path.win32.parse(p) - this.path = p.substr(parsed.root.length) - pathWarn = parsed.root + if (!this.preservePaths) { + const [root, stripped] = stripAbsolutePath(this.path) + if (root) { + this.path = stripped + pathWarn = root + } } this.win32 = !!opt.win32 || process.platform === 'win32' @@ -351,10 +352,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass { this.on('warn', opt.onwarn) let pathWarn = false - if (path.isAbsolute(this.path) && !this.preservePaths) { - const parsed = path.parse(this.path) - pathWarn = parsed.root - this.path = this.path.substr(parsed.root.length) + if (!this.preservePaths) { + const [root, stripped] = stripAbsolutePath(this.path) + if (root) { + this.path = stripped + pathWarn = root + } } this.remain = readEntry.size diff --git a/node_modules/tar/package.json b/node_modules/tar/package.json index 9b8b96ec66ca5..c497349c9397c 100644 --- a/node_modules/tar/package.json +++ b/node_modules/tar/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "name": "tar", "description": "tar for node", - "version": "6.1.0", + "version": "6.1.1", "repository": { "type": "git", "url": "https://github.com/npm/node-tar.git" @@ -38,7 +38,7 @@ "events-to-array": "^1.1.2", "mutate-fs": "^2.1.1", "rimraf": "^2.7.1", - "tap": "^14.9.2", + "tap": "^15.0.9", "tar-fs": "^1.16.3", "tar-stream": "^1.6.2" }, diff --git a/package-lock.json b/package-lock.json index d8dbcf7fe09c0..5554e8fb85af2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -144,7 +144,7 @@ "rimraf": "^3.0.2", "semver": "^7.3.5", "ssri": "^8.0.1", - "tar": "^6.1.0", + "tar": "^6.1.1", "text-table": "~0.2.0", "tiny-relative-date": "^1.3.0", "treeverse": "^1.0.4", @@ -9456,9 +9456,9 @@ } }, "node_modules/tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.1.tgz", + "integrity": "sha512-GG0R7yt/CQkvG4fueXDi52Zskqxe2AyRJ+Wm54yqarnBgcX3qRIWh10qLVAAN+mlPFGTfP5UxvD3Fbi11UOTUQ==", "inBundle": true, "dependencies": { "chownr": "^2.0.0", @@ -17396,9 +17396,9 @@ } }, "tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.1.tgz", + "integrity": "sha512-GG0R7yt/CQkvG4fueXDi52Zskqxe2AyRJ+Wm54yqarnBgcX3qRIWh10qLVAAN+mlPFGTfP5UxvD3Fbi11UOTUQ==", "requires": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", diff --git a/package.json b/package.json index fd60267ed1f02..cef491ace151d 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "rimraf": "^3.0.2", "semver": "^7.3.5", "ssri": "^8.0.1", - "tar": "^6.1.0", + "tar": "^6.1.1", "text-table": "~0.2.0", "tiny-relative-date": "^1.3.0", "treeverse": "^1.0.4",