Merge pull request #16629 from owncloud/files-renametoreservedname
Check target name on rename with web UI
This commit is contained in:
commit
5a38964218
|
@ -74,6 +74,17 @@ class App {
|
||||||
'data' => NULL
|
'data' => NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// check if the new name is conform to file name restrictions
|
||||||
|
$this->view->verifyPath($dir, $newname);
|
||||||
|
} catch (\OCP\Files\InvalidPathException $ex) {
|
||||||
|
$result['data'] = array(
|
||||||
|
'message' => $this->l10n->t($ex->getMessage()),
|
||||||
|
'code' => 'invalidname',
|
||||||
|
);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
$normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
|
$normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
|
||||||
$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
|
$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
|
||||||
|
|
||||||
|
|
|
@ -222,36 +222,17 @@ class Test_OC_Files_App_Rename extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test move to a folder that doesn't exist any more
|
* Test move to invalid name
|
||||||
*/
|
*/
|
||||||
function testRenameToNonExistingFolder() {
|
function testRenameToInvalidName() {
|
||||||
$dir = '/';
|
$dir = '/';
|
||||||
$oldname = 'oldname';
|
$oldname = 'oldname';
|
||||||
$newname = '/unexist/newname';
|
$newname = 'abc\\';
|
||||||
|
|
||||||
$this->viewMock->expects($this->any())
|
|
||||||
->method('file_exists')
|
|
||||||
->with($this->anything())
|
|
||||||
->will($this->returnValueMap(array(
|
|
||||||
array('/oldname', true),
|
|
||||||
array('/unexist', false)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->viewMock->expects($this->any())
|
|
||||||
->method('getFileInfo')
|
|
||||||
->will($this->returnValue(array(
|
|
||||||
'fileid' => 123,
|
|
||||||
'type' => 'dir',
|
|
||||||
'mimetype' => 'httpd/unix-directory',
|
|
||||||
'size' => 18,
|
|
||||||
'etag' => 'abcdef',
|
|
||||||
'directory' => '/unexist',
|
|
||||||
'name' => 'new_name',
|
|
||||||
)));
|
|
||||||
|
|
||||||
$result = $this->files->rename($dir, $oldname, $newname);
|
$result = $this->files->rename($dir, $oldname, $newname);
|
||||||
|
|
||||||
$this->assertFalse($result['success']);
|
$this->assertFalse($result['success']);
|
||||||
$this->assertEquals('targetnotfound', $result['data']['code']);
|
$this->assertEquals('File name contains at least one invalid character', $result['data']['message']);
|
||||||
|
$this->assertEquals('invalidname', $result['data']['code']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue