diff --git a/src/emulation/shared.ts b/src/emulation/shared.ts index 54ec3d28..d39b712e 100644 --- a/src/emulation/shared.ts +++ b/src/emulation/shared.ts @@ -103,7 +103,7 @@ export function resolveMount(path: string, ctx: V_Context): ResolvedMount { const sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // descending order of the string length for (const [mountPoint, fs] of sortedMounts) { // We know path is normalized, so it would be a substring of the mount point. - if (mountPoint.length <= path.length && path.startsWith(mountPoint)) { + if (_isParentOf(mountPoint, path)) { path = path.slice(mountPoint.length > 1 ? mountPoint.length : 0); // Resolve the path relative to the mount point if (path === '') { path = root; @@ -219,3 +219,14 @@ export function chroot(this: T & V_Context, path: string, i } return bindContext(join(this?.root || '/', path), creds); } + +/** + * @internal @hidden + */ +function _isParentOf(parent: string, child: string): boolean { + if (parent === '/' || parent === child) return true; + + if (!parent.endsWith('/')) parent += '/'; + + return child.startsWith(parent); +}