Skip to content

Commit

Permalink
fix(fslib): handle .zip in the middle of file name again (#3042)
Browse files Browse the repository at this point in the history
* fix(fslib): handle .zip in the middle of file name again

* Update ZipOpenFS.ts

* chore: update hook

* chore: versions

Co-authored-by: Maël Nison <[email protected]>
Co-authored-by: merceyz <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2021
1 parent 84aa9e7 commit 7b97a5d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
15 changes: 11 additions & 4 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .yarn/versions/5f918c2c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/fslib": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/pnp": patch

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/json-proxy"
- "@yarnpkg/pnpify"
- "@yarnpkg/shell"
17 changes: 12 additions & 5 deletions packages/yarnpkg-fslib/sources/ZipOpenFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ 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;
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;

const nextCharIdx = idx + DOT_ZIP.length;
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
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

0 comments on commit 7b97a5d

Please sign in to comment.