mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
11 lines
375 B
TypeScript
11 lines
375 B
TypeScript
import { isAbsolute, relative, sep } from "node:path";
|
|
|
|
/** Test lexical containment on the host platform; callers must resolve symlinks first. */
|
|
export const isPathWithinRoot = (root: string, path: string): boolean => {
|
|
const value = relative(root, path);
|
|
return (
|
|
value === "" ||
|
|
(value !== ".." && !value.startsWith(`..${sep}`) && !isAbsolute(value))
|
|
);
|
|
};
|