Skip to content

Commit

Permalink
(Closes #93) libs/mkdirs: prevent stack overflow if drive is not moun…
Browse files Browse the repository at this point in the history
…ted in Windows
  • Loading branch information
jprichardson committed Apr 18, 2016
1 parent 76dcfa9 commit a0cb04b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions lib/mkdirs/__tests__/issue-93.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var assert = require('assert')
var path = require('path')
var os = require('os')
var fse = require(process.cwd())

/* global before, describe, it */

describe('mkdirp: issue-93, win32, when drive does not exist, it should return a cleaner error', function () {
var TEST_DIR

// only seems to be an issue on Windows.
if (process.platform !== 'win32') return

before(function (done) {
TEST_DIR = path.join(os.tmpdir(), 'tests', 'fs-extra', 'mkdirp-issue-93')
fse.emptyDir(TEST_DIR, function (err) {
assert.ifError(err)
done()
})
})

it('should return a cleaner error than inifinite loop, stack crash', function (done) {
var file = 'R:\\afasd\\afaff\\fdfd' // hopefully drive 'r' does not exist on appveyor
fse.mkdirp(file, function (err) {
assert.strictEqual(err.code, 'ENOENT')

try {
fse.mkdirsSync(file)
} catch (err) {
assert.strictEqual(err.code, 'ENOENT')
}

done()
})
})
})
3 changes: 2 additions & 1 deletion lib/mkdirs/mkdirs-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function mkdirsSync (p, opts, made) {
made = made || p
} catch (err0) {
switch (err0.code) {
case 'ENOENT' :
case 'ENOENT':
if (path.dirname(p) === p) throw err0
made = mkdirsSync(path.dirname(p), opts, made)
mkdirsSync(p, opts, made)
break
Expand Down

0 comments on commit a0cb04b

Please sign in to comment.