diff --git a/lib/fs.js b/lib/fs.js index ed1914a..98d458f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -74,12 +74,13 @@ var twoPathMethods = [ */ exports.create = function (options) { var pwd = options.pwd; - if (typeof pwd === 'string') { - var _pwd = pwd; + if ('function' !== (typeof pwd)) { + var _pwd = ('string' === (typeof pwd)) ? pwd : process.env.PWD; pwd = function () { return _pwd; }; } + var _limitRootDir = options.limitRoot || pwd(); _limitRootDir = _limitRootDir.replace(/\/+$/, '') + '/'; diff --git a/test/fs.test.js b/test/fs.test.js index ec1d967..570d7c3 100644 --- a/test/fs.test.js +++ b/test/fs.test.js @@ -306,6 +306,12 @@ describe('fs.test.js', function () { fs.renameSync('../../../../../etc/hosts', 'foo/bar/rename_hosts.js'); }).should.throw("EACCES, permission denied '../../../../../etc/hosts'"); }); + + it('should undefined function pwd works fine', function () { + var yafs = require('../').create({ + limitRoot: path.join(__dirname, 'fixtures'), + }); + }); }); });