fs.rename() should normalize paths before using, dir vs. dir/

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2015-05-12 15:16:32 -04:00
parent e9c4cb6d7a
commit 17fb8993c3
3 changed files with 32 additions and 0 deletions

View File

@ -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);

View File

@ -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();
});
});
});
});
});

View File

@ -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");