From e6eeb3da5bcde62d242c2915c50a50539022a258 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Thu, 27 Feb 2020 06:59:46 -0600 Subject: [PATCH] Handle dots within filenames --- fixtures/edge_case_dots.tar.gz | Bin 0 -> 211 bytes index.js | 2 +- test.js | 6 ++++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 fixtures/edge_case_dots.tar.gz diff --git a/fixtures/edge_case_dots.tar.gz b/fixtures/edge_case_dots.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..c51458079a678a8f9e25e0b365def16efd1f07bb GIT binary patch literal 211 zcmV;^04)C>iwFS9xmR8Q1MQPR3WG2ZMP2t4If0EanVg`Do43PR~rDk&LHqyQB$6=a(Q z_ul56Tcv25+N|7r+z^|U^ZBEg=PiSQbN{um*qOW;x;VB^>tTlb4{%z4`%hruUuy{w z;~r*ja&Z6GNjQ58KmB_fVs94tM^o0On$quU#&-VYH~&Jo`~#$%^1la{K{%zKAPC}U Nya1>-pL+lf001c9Vv7I( literal 0 HcmV?d00001 diff --git a/index.js b/index.js index ba3ec6a..19bc34f 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ const extractFile = (input, output, opts) => runPlugins(input, opts).then(files return Promise.all(files.map(x => { const dest = path.join(output, x.path); - if (dest.match(/\.\./)) { + if (dest.match(/\.\.\//)) { throw (new Error('File path contains "..":', dest)); } diff --git a/test.js b/test.js index 04bcc28..19f5665 100644 --- a/test.js +++ b/test.js @@ -109,3 +109,9 @@ test('throw when a location outside the root is given', async t => { await m(path.join(__dirname, 'fixtures', 'slipping.tar.gz'), 'dist'); }, {message: /File path contains "\.\."/}); }); + +test('allows filenames to be written with dots in them', async t => { + const files = await m(path.join(__dirname, 'fixtures', 'edge_case_dots.tar.gz'), __dirname); + t.is(files.length, 3); + await fsP.rmdir(path.join(__dirname, 'edge_case_dots'), {recursive: true}); +});