Skip to content

Commit

Permalink
fix(fslib): handle .zip in the middle of file name again
Browse files Browse the repository at this point in the history
  • Loading branch information
ratson committed Jul 8, 2021
1 parent 3972f96 commit ee5f023
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/yarnpkg-fslib/sources/ZipOpenFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ const DOT_ZIP = `.zip`;
* The indexOf-based implementation is ~3.7x faster than a RegExp-based implementation.
*/
export const getArchivePart = (path: string) => {
const idx = path.indexOf(DOT_ZIP);
let idx = path.indexOf(DOT_ZIP);
if (idx <= 0)
return null;

// Disallow files named ".zip"
if (path[idx - 1] === ppath.sep)
return null;

const nextCharIdx = idx + DOT_ZIP.length;
let nextCharIdx = idx;
while (idx >= 0) {
nextCharIdx = idx + DOT_ZIP.length;
if (path[nextCharIdx] === ppath.sep)
break;
// Disallow files named ".zip"
if (path[idx - 1] === ppath.sep)
return null;
idx = path.indexOf(DOT_ZIP, nextCharIdx);
}

// The path either has to end in ".zip" or contain an archive subpath (".zip/...")
if (path.length > nextCharIdx && path[nextCharIdx] !== ppath.sep)
Expand Down
3 changes: 3 additions & 0 deletions packages/yarnpkg-fslib/tests/ZipOpenFS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe(`getArchivePart`, () => {
[`./a/b/c/.zip`, null],
[`./a/b/c/foo.zipp`, null],
[`./a/b/c/foo.zip/bar/baz/qux.zip`, `./a/b/c/foo.zip`],
[`./a/b/c/foo.zip-bar.zip`, `./a/b/c/foo.zip-bar.zip`],
[`./a/b/c/foo.zip-bar.zip/bar/baz/qux.zip`, `./a/b/c/foo.zip-bar.zip`],
[`./a/b/c/foo.zip-bar/foo.zip-bar/foo.zip-bar.zip/d`, `./a/b/c/foo.zip-bar/foo.zip-bar/foo.zip-bar.zip`],
] as const;

for (const [path, result] of tests) {
Expand Down

0 comments on commit ee5f023

Please sign in to comment.