diff --git a/packages/yarnpkg-fslib/sources/ZipOpenFS.ts b/packages/yarnpkg-fslib/sources/ZipOpenFS.ts index 2f7e77444058..6e62537881ef 100644 --- a/packages/yarnpkg-fslib/sources/ZipOpenFS.ts +++ b/packages/yarnpkg-fslib/sources/ZipOpenFS.ts @@ -21,20 +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; - - 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; + 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)