From 3a9570386a1cae3f9c787899f297bfd3816c905d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 9 Sep 2010 18:49:28 -0700 Subject: [PATCH] Fix fs.realpathSync('/') --- lib/fs.js | 4 +++- test/simple/test-fs-realpath.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 5cdbb1cd1c..abbb11d673 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -519,8 +519,10 @@ function realpathSync (p) { i = 0; buf = ['']; } - return buf.join('/'); + return buf.join('/') || '/'; } + + function realpath (p, cb) { if (p.charAt(0) !== '/') { p = path.join(process.cwd(), p); diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js index c845e8cbe2..dc08fd63fd 100644 --- a/test/simple/test-fs-realpath.js +++ b/test/simple/test-fs-realpath.js @@ -260,6 +260,15 @@ function runNextTest(err) { } runNextTest(); + +assert.equal('/', fs.realpathSync('/')); +fs.realpath('/', function (err, result) { + assert.equal(null, err); + assert.equal('/', result); +}); + + + process.addListener("exit", function () { unlink.forEach(function(path){ try {fs.unlinkSync(path);}catch(e){} }); assert.equal(async_completed, async_expected);