From 17fb8993c34ef99549d4c98c6c4eb038cd019cd4 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Tue, 12 May 2015 15:16:32 -0400 Subject: [PATCH] fs.rename() should normalize paths before using, dir vs. dir/ --- src/filesystem/implementation.js | 3 +++ tests/bugs/rename-dir-trailing-slash.js | 28 +++++++++++++++++++++++++ tests/index.js | 1 + 3 files changed, 32 insertions(+) create mode 100644 tests/bugs/rename-dir-trailing-slash.js diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index ca6f4ef..0dde525 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1976,6 +1976,9 @@ function rename(fs, context, oldpath, newpath, callback) { if(!pathCheck(oldpath, callback)) return; if(!pathCheck(newpath, callback)) return; + oldpath = normalize(oldpath); + newpath = normalize(newpath); + var oldParentPath = Path.dirname(oldpath); var newParentPath = Path.dirname(oldpath); var oldName = Path.basename(oldpath); diff --git a/tests/bugs/rename-dir-trailing-slash.js b/tests/bugs/rename-dir-trailing-slash.js new file mode 100644 index 0000000..83c96c0 --- /dev/null +++ b/tests/bugs/rename-dir-trailing-slash.js @@ -0,0 +1,28 @@ +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('trailing slashes in path names to work when renaming a dir', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should deal with trailing slashes in rename, dir == dir/', function(done) { + var fs = util.fs(); + + fs.mkdir('/tmp', function(err) { + if(err) throw err; + + fs.rename('/tmp/', '/new-tmp/', function(err) { + if(err) throw err; + + fs.stat('/new-tmp', function(err, stats) { + if(err) throw err; + expect(stats).to.exist; + expect(stats.isDirectory()).to.be.true; + + done(); + }); + }); + }); + }); +}); diff --git a/tests/index.js b/tests/index.js index 7e9d0ec..ec2b849 100644 --- a/tests/index.js +++ b/tests/index.js @@ -75,3 +75,4 @@ require("./bugs/issue254.js"); require("./bugs/issue258.js"); require("./bugs/issue267.js"); require("./bugs/issue270.js"); +require("./bugs/rename-dir-trailing-slash.js");