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 Jun 24, 2021
1 parent 5ebd914 commit b730180
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/yarnpkg-fslib/sources/ZipOpenFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b730180

Please sign in to comment.