path.isAbsolute(path)
path.isAbsolute()
方法确定字面量 path
是否为绝对值。因此,它对于缓解路径遍历并不安全。
¥The path.isAbsolute()
method determines if the literal path
is absolute.
Therefore, it’s not safe for mitigating path traversals.
如果给定的 path
是零长度字符串,则将返回 false
。
¥If the given path
is a zero-length string, false
will be returned.
例如,在 POSIX 上:
¥For example, on POSIX:
path.isAbsolute('/foo/bar'); // true
path.isAbsolute('/baz/..'); // true
path.isAbsolute('/baz/../..'); // true
path.isAbsolute('qux/'); // false
path.isAbsolute('.'); // false
在 Windows 上:
¥On Windows:
path.isAbsolute('//server'); // true
path.isAbsolute('\\\\server'); // true
path.isAbsolute('C:/foo/..'); // true
path.isAbsolute('C:\\foo\\..'); // true
path.isAbsolute('bar\\baz'); // false
path.isAbsolute('bar/baz'); // false
path.isAbsolute('.'); // false
如果 path
不是字符串,则抛出 TypeError
。
¥A TypeError
is thrown if path
is not a string.