Skip to content

Commit

Permalink
Fix: browser traverse (#309)
Browse files Browse the repository at this point in the history
* Revert "fix: make getChildEntry recursively traverse the path (#301)"

This reverts commit ed6c88b.

* fix: possible browser traversal fix
  • Loading branch information
guybedford committed Dec 14, 2023
1 parent 5981b3e commit ffe046b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/preview2-shim/lib/browser/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ function getChildEntry (parentEntry, subpath, openFlags) {
let segmentIdx;
do {
if (!entry || !entry.dir) throw 'not-directory';
segmentIdx = subpath.indexOf('/', segmentIdx);
segmentIdx = subpath.indexOf('/');
const segment = segmentIdx === -1 ? subpath : subpath.slice(0, segmentIdx);
if (segment === '.' || segment === '')
/* continue traversing */;
else if (segment === '..')
throw 'no-entry';
if (segment === '..') throw 'no-entry';
if (segment === '.' || segment === '');
else if (!entry.dir[segment] && openFlags.create)
entry = entry.dir[segment] = openFlags.directory ? { dir: {} } : { source: new Uint8Array([]) };
else
entry = entry.dir[segment];
subpath = subpath.substring(segmentIdx + 1);
} while (segmentIdx !== -1);
subpath = subpath.slice(segmentIdx + 1);
} while (segmentIdx !== -1)
if (!entry) throw 'no-entry';
return entry;
}
Expand Down

0 comments on commit ffe046b

Please sign in to comment.