Skip to content

Commit ed6c88b

Browse files
authored
fix: make getChildEntry recursively traverse the path (#301)
* fix: make getChildEntry recursively traverse the path * fix: don't assign `entry = entry;`
1 parent 774cac5 commit ed6c88b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/preview2-shim/lib/browser/filesystem.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ function getChildEntry (parentEntry, subpath, openFlags) {
3737
let segmentIdx;
3838
do {
3939
if (!entry || !entry.dir) throw 'not-directory';
40-
segmentIdx = subpath.indexOf('/');
40+
segmentIdx = subpath.indexOf('/', segmentIdx);
4141
const segment = segmentIdx === -1 ? subpath : subpath.slice(0, segmentIdx);
42-
if (segment === '.' || segment === '') return entry;
43-
if (segment === '..') throw 'no-entry';
44-
if (!entry.dir[segment] && openFlags.create)
42+
if (segment === '.' || segment === '')
43+
/* continue traversing */;
44+
else if (segment === '..')
45+
throw 'no-entry';
46+
else if (!entry.dir[segment] && openFlags.create)
4547
entry = entry.dir[segment] = openFlags.directory ? { dir: {} } : { source: new Uint8Array([]) };
4648
else
4749
entry = entry.dir[segment];
48-
} while (segmentIdx !== -1)
50+
subpath = subpath.substring(segmentIdx + 1);
51+
} while (segmentIdx !== -1);
4952
if (!entry) throw 'no-entry';
5053
return entry;
5154
}

0 commit comments

Comments
 (0)