diff --git a/tap-snapshots/test/unpack.js.test.cjs b/tap-snapshots/test/unpack.js.test.cjs new file mode 100644 index 00000000..2446eb2e --- /dev/null +++ b/tap-snapshots/test/unpack.js.test.cjs @@ -0,0 +1,18 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/unpack.js > TAP > ignore self-referential hardlinks > async > must match snapshot 1`] = ` +Array [ + "ENOENT: no such file or directory, link '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-async/autolink' -> '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-async/autolink'", +] +` + +exports[`test/unpack.js > TAP > ignore self-referential hardlinks > sync > must match snapshot 1`] = ` +Array [ + "ENOENT: no such file or directory, link '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-sync/autolink' -> '{CWD}/.tap/fixtures/test-unpack.js-ignore-self-referential-hardlinks-sync/autolink'", +] +` diff --git a/test/unpack.js b/test/unpack.js index 2f167a30..bcffa0c9 100644 --- a/test/unpack.js +++ b/test/unpack.js @@ -1,6 +1,6 @@ import { Unpack, UnpackSync } from '../dist/esm/unpack.js' -import fs from 'fs' +import fs, { readdirSync } from 'fs' import { Minipass } from 'minipass' import * as z from 'minizlib' import path from 'path' @@ -3531,3 +3531,35 @@ t.test('excessively deep subfolder nesting', async t => { check(t, 64) }) }) + +t.test('ignore self-referential hardlinks', async t => { + const data = makeTar([ + { + path: 'autolink', + linkpath: './autolink', + type: 'Link', + }, + ]) + const check = (t, warnings) => { + t.matchSnapshot(warnings) + t.strictSame(readdirSync(t.testdirName), [], 'nothing extracted') + t.end() + } + t.test('async', t => { + const cwd = t.testdir({}) + const warnings = [] + const u = new Unpack({ cwd, onwarn: (_, m) => warnings.push(m) }) + u.on('end', () => check(t, warnings)) + u.end(data) + }) + t.test('sync', t => { + const cwd = t.testdir({}) + const warnings = [] + const u = new UnpackSync({ + cwd, + onwarn: (_, m) => warnings.push(m), + }) + u.end(data) + check(t, warnings) + }) +})