query
On this page

isValid

lib.path.subpath.isValid

Docs pulled from | This Revision | 11 minutes ago


Whether a value is a valid subpath string.

A subpath string points to a specific file or directory within an absolute base directory. It is a stricter form of a relative path that excludes .. components, since those could escape the base directory.

  • The value is a string.

  • The string is not empty.

  • The string doesn't start with a /.

  • The string doesn't contain any .. path components.

Inputs

value

The value to check

Type

subpath.isValid :: String -> Bool

Examples

subpath.isValid usage example

# Not a string
subpath.isValid null
=> false

# Empty string
subpath.isValid ""
=> false

# Absolute path
subpath.isValid "/foo"
=> false

# Contains a `..` path component
subpath.isValid "../foo"
=> false

# Valid subpath
subpath.isValid "foo/bar"
=> true

# Doesn't need to be normalised
subpath.isValid "./foo//bar/"
=> true

Noogle detected

Implementation

The following is the current implementation of this function.

subpath.isValid =
    # The value to check
    value: subpathInvalidReason value == null;