|
| 1 | +import t from 'tap' |
| 2 | +import { normalizeUnicode } from '../src/normalize-unicode.js' |
| 3 | +import { Header } from '../src/header.js' |
| 4 | +import { extract } from '../src/extract.js' |
| 5 | +import { resolve } from 'node:path' |
| 6 | +import { lstatSync, readFileSync, statSync } from 'node:fs' |
| 7 | + |
| 8 | +// these characters are problems on macOS's APFS |
| 9 | +const chars = { |
| 10 | + ['ff'.normalize('NFC')]: 'FF', |
| 11 | + ['fi'.normalize('NFC')]: 'FI', |
| 12 | + ['fl'.normalize('NFC')]: 'FL', |
| 13 | + ['ffi'.normalize('NFC')]: 'FFI', |
| 14 | + ['ffl'.normalize('NFC')]: 'FFL', |
| 15 | + ['ſt'.normalize('NFC')]: 'ST', |
| 16 | + ['st'.normalize('NFC')]: 'ST', |
| 17 | + ['ẛ'.normalize('NFC')]: 'Ṡ', |
| 18 | + ['ß'.normalize('NFC')]: 'SS', |
| 19 | + ['ẞ'.normalize('NFC')]: 'SS', |
| 20 | + ['ſ'.normalize('NFC')]: 'S', |
| 21 | +} |
| 22 | + |
| 23 | +for (const [c, n] of Object.entries(chars)) { |
| 24 | + t.test(`${c} => ${n}`, async t => { |
| 25 | + t.equal(normalizeUnicode(c), n) |
| 26 | + |
| 27 | + t.test('link then file', async t => { |
| 28 | + const tarball = Buffer.alloc(2048) |
| 29 | + new Header({ |
| 30 | + path: c, |
| 31 | + type: 'SymbolicLink', |
| 32 | + linkpath: './target', |
| 33 | + }).encode(tarball, 0) |
| 34 | + new Header({ |
| 35 | + path: n, |
| 36 | + type: 'File', |
| 37 | + size: 1, |
| 38 | + }).encode(tarball, 512) |
| 39 | + tarball[1024] = 'x'.charCodeAt(0) |
| 40 | + |
| 41 | + const cwd = t.testdir({ tarball }) |
| 42 | + |
| 43 | + await extract({ cwd, file: resolve(cwd, 'tarball') }) |
| 44 | + |
| 45 | + t.throws(() => statSync(resolve(cwd, 'target'))) |
| 46 | + t.equal(readFileSync(resolve(cwd, n), 'utf8'), 'x') |
| 47 | + }) |
| 48 | + |
| 49 | + t.test('file then link', { saveFixture: true }, async t => { |
| 50 | + const tarball = Buffer.alloc(2048) |
| 51 | + new Header({ |
| 52 | + path: n, |
| 53 | + type: 'File', |
| 54 | + size: 1, |
| 55 | + }).encode(tarball, 0) |
| 56 | + tarball[512] = 'x'.charCodeAt(0) |
| 57 | + new Header({ |
| 58 | + path: c, |
| 59 | + type: 'SymbolicLink', |
| 60 | + linkpath: './target', |
| 61 | + }).encode(tarball, 1024) |
| 62 | + |
| 63 | + const cwd = t.testdir({ tarball }) |
| 64 | + |
| 65 | + await extract({ cwd, file: resolve(cwd, 'tarball') }) |
| 66 | + |
| 67 | + t.throws(() => statSync(resolve(cwd, 'target'))) |
| 68 | + t.equal(lstatSync(resolve(cwd, c)).isSymbolicLink(), true) |
| 69 | + }) |
| 70 | + }) |
| 71 | +} |
0 commit comments