1 | const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform
|
2 | const { resolve, parse } = require('path')
|
3 | const pathArg = path => {
|
4 | if (/\0/.test(path)) {
|
5 |
|
6 | throw Object.assign(
|
7 | new TypeError('path must be a string without null bytes'),
|
8 | {
|
9 | path,
|
10 | code: 'ERR_INVALID_ARG_VALUE',
|
11 | }
|
12 | )
|
13 | }
|
14 |
|
15 | path = resolve(path)
|
16 | if (platform === 'win32') {
|
17 | const badWinChars = /[*|"<>?:]/
|
18 | const {root} = parse(path)
|
19 | if (badWinChars.test(path.substr(root.length))) {
|
20 | throw Object.assign(new Error('Illegal characters in path.'), {
|
21 | path,
|
22 | code: 'EINVAL',
|
23 | })
|
24 | }
|
25 | }
|
26 |
|
27 | return path
|
28 | }
|
29 | module.exports = pathArg
|