[Pkg-owncloud-commits] [owncloud] 190/457: Check target name on rename with web UI

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 13617c8bf10ed8e991757099e95da060612e7787
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Fri May 29 19:30:09 2015 +0200

    Check target name on rename with web UI
    
    When renaming over the web UI, check early that the target name is
    valid.
    
    This prevents nonsensical error messages when renaming to a name with a
    trailing backslash.
---
 apps/files/lib/app.php           | 11 +++++++++++
 apps/files/tests/ajax_rename.php | 29 +++++------------------------
 2 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php
index d80024f..5bd8c12 100644
--- a/apps/files/lib/app.php
+++ b/apps/files/lib/app.php
@@ -74,6 +74,17 @@ class App {
 			'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);
 		$normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
 
diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php
index 34e7f50..a690c7d 100644
--- a/apps/files/tests/ajax_rename.php
+++ b/apps/files/tests/ajax_rename.php
@@ -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 = '/';
 		$oldname = 'oldname';
-		$newname = '/unexist/newname';
-
-		$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',
-			)));
+		$newname = 'abc\\';
 
 		$result = $this->files->rename($dir, $oldname, $newname);
 
 		$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']);
 	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list