Skip to content

Commit

Permalink
fix(ZipOpenFS): handle .zip in the middle of file name
Browse files Browse the repository at this point in the history
  • Loading branch information
ratson committed Jun 28, 2021
1 parent 25363f1 commit a5b6e2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/yarnpkg-fslib/sources/ZipOpenFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export const getArchivePart = (path: string) => {
if (path[idx - 1] === ppath.sep)
return null;

const nextCharIdx = idx + DOT_ZIP.length;
let nextCharIdx = idx + DOT_ZIP.length;
const idxBeforeSep = path.indexOf(ppath.sep, nextCharIdx);
if (idxBeforeSep >= 0)
nextCharIdx = idxBeforeSep;
else if (path.endsWith(DOT_ZIP))
nextCharIdx = path.length;

// The path either has to end in ".zip" or contain an archive subpath (".zip/...")
if (path.length > nextCharIdx && path[nextCharIdx] !== ppath.sep)
Expand Down
2 changes: 2 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,8 @@ 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`],
] as const;

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

0 comments on commit a5b6e2e

Please sign in to comment.