Skip to content

Commit

Permalink
(Closes #209) lib/mkdirs: check for invalid WIN32 path chars
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Apr 17, 2016
1 parent 962b983 commit 94a3e89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mkdirs/__tests__/issue-209.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error
it('should return a cleaner error than inifinite loop, stack crash', function (done) {
var file = './bad?dir'
fse.mkdirp(file, function (err) {
assert.strictEqual(err.code, 'ENOENT')
assert.strictEqual(err.code, 'EINVAL')
done()
})
})
Expand Down
7 changes: 7 additions & 0 deletions lib/mkdirs/mkdirs-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ function mkdirsSync (p, opts, made) {
var mode = opts.mode
var xfs = opts.fs || fs

if (process.platform === 'win32') {
var errInval = new Error(p + ' contains invalid WIN32 path characters.')
errInval.code = 'EINVAL'
// http://stackoverflow.com/a/62888/10333 contains more accurate
if (/[<>:"|?*]/.test(p)) throw errInval
}

if (mode === undefined) {
mode = o777 & (~process.umask())
}
Expand Down
7 changes: 7 additions & 0 deletions lib/mkdirs/mkdirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ function mkdirs (p, opts, callback, made) {
opts = { mode: opts }
}

if (process.platform === 'win32') {
var errInval = new Error(p + ' contains invalid WIN32 path characters.')
errInval.code = 'EINVAL'
// http://stackoverflow.com/a/62888/10333 contains more accurate
if (/[<>:"|?*]/.test(p)) return callback(errInval)
}

var mode = opts.mode
var xfs = opts.fs || fs

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var argv = require('minimist')(process.argv.slice(2))

var mochaOpts = assign({
ui: 'bdd',
reporter: 'list',
reporter: 'dot',
timeout: 30000
}, argv)

Expand Down

0 comments on commit 94a3e89

Please sign in to comment.