Skip to content

Commit

Permalink
(#93, #209) prevent stack overflow if bad dir on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Apr 17, 2016
1 parent f5c1e80 commit 1b73ffe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/mkdirs/__tests__/README.md

This file was deleted.

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()
})
})
})
1 change: 1 addition & 0 deletions lib/mkdirs/mkdirs-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function mkdirsSync (p, opts, made) {
} catch (err0) {
switch (err0.code) {
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 1b73ffe

Please sign in to comment.