From dcbf246b3512fd057a7799b0e0268efdc6798d49 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Wed, 18 May 2016 17:22:17 +0530 Subject: [PATCH] fs: mkdtemp shouldn't crash if no callback passed As it is, `fs.mkdtemp` crashes with a C++ assertion if the callback function is not passed. This patch uses `maybeCallback` to create one, if no callback function is passed. PR-URL: https://github.com/nodejs/node/pull/6828 Reviewed-By: Brian White Reviewed-By: James M Snell --- lib/fs.js | 3 ++- test/parallel/test-fs-mkdtemp.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index f0ad82cfb1..9a6eaa9b08 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2000,7 +2000,8 @@ SyncWriteStream.prototype.destroy = function() { SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy; -fs.mkdtemp = function(prefix, options, callback) { +fs.mkdtemp = function(prefix, options, callback_) { + var callback = maybeCallback(callback_); if (!prefix || typeof prefix !== 'string') throw new TypeError('filename prefix is required'); diff --git a/test/parallel/test-fs-mkdtemp.js b/test/parallel/test-fs-mkdtemp.js index ad8a6cb46e..d3def97fef 100644 --- a/test/parallel/test-fs-mkdtemp.js +++ b/test/parallel/test-fs-mkdtemp.js @@ -25,3 +25,5 @@ fs.mkdtemp( assert(common.fileExists(folder)); }) ); + +assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));