[F] sanitizePathSegment
function sanitizePathSegment(value): string;Sanitize a value so it is safe to use as a single segment of a path.
Path separators, drive letter separators and NUL are replaced with _ and values only made of .(e.g. . or ..) are replaced with _.
This prevents values coming from a TypeSpec spec(e.g. a version or a service name) from escaping the directory the file was meant to be written to.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | Value to sanitize. |
Returns
Section titled “Returns”string
Example
Section titled “Example”sanitizePathSegment("2021-10-01-preview"); // "2021-10-01-preview"sanitizePathSegment("../../etc/passwd"); // ".._.._etc_passwd"