mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
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:
parent
a3e622ba0d
commit
2da9ab55be
@ -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));
|
||||
}
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
10
test/ls.js
10
test/ls.js
@ -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);
|
||||
});
|
||||
|
||||
@ -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`));
|
||||
});
|
||||
|
||||
@ -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`));
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user