-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…allback OR throw err
- Loading branch information
1 parent
a0cb04b
commit 8c56e5b
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var assert = require('assert') | ||
var fse = require(process.cwd()) | ||
|
||
/* global describe, it */ | ||
|
||
describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error', function () { | ||
// only seems to be an issue on Windows. | ||
if (process.platform !== 'win32') return | ||
|
||
it('should return a callback', function (done) { | ||
var file = './bad?dir' | ||
fse.mkdirp(file, function (err) { | ||
assert(err, 'error is present') | ||
assert.strictEqual(err.code, 'EINVAL') | ||
|
||
var file2 = 'c:\\tmp\foo:moo' | ||
fse.mkdirp(file2, function (err) { | ||
assert(err, 'error is present') | ||
assert.strictEqual(err.code, 'EINVAL') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('> sync', function () { | ||
it('should throw an error', function () { | ||
var didErr | ||
try { | ||
var file = 'c:\\tmp\foo:moo' | ||
fse.mkdirpSync(file) | ||
} catch (err) { | ||
// console.error(err) | ||
didErr = true | ||
} | ||
assert(didErr) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
var path = require('path') | ||
|
||
// get drive on windows | ||
function getRootPath (p) { | ||
p = path.normalize(path.resolve(p)).split(path.sep) | ||
if (p.length > 0) return p[0] | ||
else return null | ||
} | ||
|
||
// http://stackoverflow.com/a/62888/10333 contains more accurate | ||
// TODO: expand to include the rest | ||
var INVALID_PATH_CHARS = /[<>:"|?*]/ | ||
|
||
function invalidWin32Path (p) { | ||
var rp = getRootPath(p) | ||
p = p.replace(rp, '') | ||
return INVALID_PATH_CHARS.test(p) | ||
} | ||
|
||
module.exports = { | ||
getRootPath: getRootPath, | ||
invalidWin32Path: invalidWin32Path | ||
} |