Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
730 bytes
|
Line | |
---|
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 | // simulate same failure that node raises
|
---|
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
|
---|
Note:
See
TracBrowser
for help on using the repository browser.