fix: allow non-normalized paths as input to mkdir (#635)

Adds tests to make sure that non-normalized paths (i.e. path/to/./dir) are
valid for a few commands, including mkdir() which previously failed when given
the -p flag.

Fixes #634
This commit is contained in:
Nate Fischer 2017-01-07 18:06:15 -08:00 committed by Brandon Freitag
parent a3e622ba0d
commit 2da9ab55be
5 changed files with 34 additions and 2 deletions

View File

@ -75,7 +75,7 @@ function _mkdir(options, dirs) {
try {
if (options.fullpath) {
mkdirSyncRecursive(dir);
mkdirSyncRecursive(path.resolve(dir));
} else {
fs.mkdirSync(dir, parseInt('0777', 8));
}

View File

@ -259,7 +259,6 @@ test(
);
test('recursive, everything exists, no force flag', t => {
shell.cp('-R', 'resources/cp', t.context.tmp);
const result = shell.cp('-R', 'resources/cp', t.context.tmp);
t.falsy(shell.error()); // crash test only
t.falsy(result.stderr);
@ -647,3 +646,10 @@ test('Test with recursive option and symlinks.', t => {
t.falsy(shell.test('-L', 'sym.lnk'));
});
});
test('recursive, with a non-normalized path', t => {
const result = shell.cp('-R', 'resources/../resources/./cp', t.context.tmp);
t.falsy(shell.error()); // crash test only
t.falsy(result.stderr);
t.is(result.code, 0);
});

View File

@ -466,3 +466,13 @@ test('Check stderr field', t => {
t.truthy(shell.error());
t.is('ls: no such file or directory: /asdfasdf', result.stderr);
});
test('non-normalized paths are still ok with -R', t => {
const result = shell.ls('-R', 'resources/./ls/../ls');
t.falsy(shell.error());
t.is(result.code, 0);
t.truthy(result.indexOf('a_dir') > -1);
t.truthy(result.indexOf('a_dir/b_dir') > -1);
t.truthy(result.indexOf('a_dir/b_dir/z') > -1);
t.is(result.length, 9);
});

View File

@ -147,3 +147,10 @@ test('globbed dir', t => {
t.truthy(fs.existsSync(`${t.context.tmp}/mydir`));
t.falsy(fs.existsSync(`${t.context.tmp}/m*ir`)); // doesn't create literal name
});
test('non-normalized paths are still ok with -p', t => {
const result = shell.mkdir('-p', `${t.context.tmp}/asdf/../asdf/./`);
t.falsy(shell.error());
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/asdf`));
});

View File

@ -282,3 +282,12 @@ test('remove broken symbolic link', t => {
t.falsy(fs.existsSync(`${t.context.tmp}/rm/fake.lnk`));
}
});
test('recursive dir removal, for non-normalized path', t => {
shell.mkdir('-p', `${t.context.tmp}/a/b/c`);
t.truthy(fs.existsSync(`${t.context.tmp}/a/b/c`));
const result = shell.rm('-rf', `${t.context.tmp}/a/.././a`);
t.falsy(shell.error());
t.is(result.code, 0);
t.falsy(fs.existsSync(`${t.context.tmp}/a`));
});