[]previous and next page

safeJoin

Joins a project-relative file path to the target, refusing anything that could land outside it: absolute paths, drive letters, .. segments, NUL bytes and backslashes.

Joins a project-relative file path to the target, refusing anything that could land outside it: absolute paths, drive letters, .. segments, NUL bytes and backslashes.

Import#

ts
import { safeJoin } from "create-shadow-app";

Signature#

ts
function safeJoin(target: string, file: string, path: PathApi = nodePath): string

Parameters#

Name Description
target Absolute project directory.
file Relative POSIX path from the file map.
path The path functions of the platform. Default: this machine's.

Returns#

The absolute path of the file.

Throws#

  • Error when the path would escape target.

Examples#

ts
safeJoin("/work/app", "src/main.tsx"); // "/work/app/src/main.tsx"