Browse Source

OC-2107: Change validation name method: ValidateName and ValidatePath

masensio 11 years ago
parent
commit
4a4d78821a

+ 11 - 26
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java

@@ -38,19 +38,17 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 	 */
 	public void testCreateFolder() {
 
-		String folderName = "testCreateFolder" + mCurrentDate;
 		String remotePath = "/testCreateFolder" + mCurrentDate;
 		boolean createFullPath = true;
 		
-		RemoteOperationResult result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 		
 		// Create Subfolder
-		folderName = "testCreateFolder" + mCurrentDate;
 		remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
 		createFullPath = true;
 		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 	}
 	
@@ -61,49 +59,36 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 	public void testCreateFolderSpecialCharacters() {		
 		boolean createFullPath = true;
 		
-		String folderName = "testSpecialCharacters_//" + mCurrentDate;
-		String remotePath = "/testSpecialCharacters_//" + mCurrentDate;
-		RemoteOperationResult result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		String remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
+		RemoteOperationResult result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_\\" + mCurrentDate;
-		remotePath = "/testSpecialCharacters_\\" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
-		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
-		
-		folderName = "testSpecialCharacters_<" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_<" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_>" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_>" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_:" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_:" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_\"" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_\"" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_|" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_|" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_?" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_?" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 		
-		folderName = "testSpecialCharacters_*" + mCurrentDate;
 		remotePath = "/testSpecialCharacters_*" + mCurrentDate;		
-		result =  mActivity.createFolder(folderName, remotePath, createFullPath);
+		result =  mActivity.createFolder(remotePath, createFullPath);
 		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 	}
 

+ 2 - 3
oc_framework-test-project/src/com/owncloud/android/oc_framework_test_project/TestActivity.java

@@ -88,14 +88,13 @@ public class TestActivity extends Activity {
 
 	/**
 	 * Access to the library method to Create a Folder
-	 * @param folderName
 	 * @param remotePath
 	 * @param createFullPath
 	 * @return
 	 */
-	public RemoteOperationResult createFolder(String folderName, String remotePath, boolean createFullPath) {
+	public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
 		
-		CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(folderName, remotePath, createFullPath);
+		CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
 		RemoteOperationResult result =  createOperation.execute(mClient);
 		
 		return result;

+ 3 - 6
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java

@@ -29,19 +29,16 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
     private static final int CONNECTION_TIMEOUT = 5000;
     
 
-    protected String mFolderName;
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     
     /**
      * Constructor
      * 
-     * @param folderName			Name of new directory
      * @param remotePath            Full path to the new directory to create in the remote server.
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      */
-    public CreateRemoteFolderOperation(String folderName, String remotePath, boolean createFullPath) {
-    	mFolderName = folderName;
+    public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) {
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
     }
@@ -56,7 +53,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
-        boolean noInvalidChars = FileUtils.validateName(mFolderName);
+        boolean noInvalidChars = FileUtils.validatePath(mRemotePath);
         if (noInvalidChars) {
         	try {
         		mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
@@ -87,7 +84,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
 
     
     private RemoteOperationResult createParentFolder(String parentPath, WebdavClient client) {
-        RemoteOperation operation = new CreateRemoteFolderOperation("", parentPath,
+        RemoteOperation operation = new CreateRemoteFolderOperation(parentPath,
                                                                 mCreateFullPath);
         return operation.execute(client);
     }

+ 18 - 2
oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java

@@ -24,8 +24,7 @@ public class FileUtils {
 		boolean result = true;
 		
 		Log.d("FileUtils", "fileName =======" + fileName);
-		String name = fileName.substring(1);
-		if ((fileName.indexOf("/") > 0 && name.indexOf("/") < (name.length() - 1 ) ) || 
+		if (fileName.contains(PATH_SEPARATOR) ||
 				fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
 				fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") || 
 				fileName.contains("?") || fileName.contains("*")) {
@@ -33,4 +32,21 @@ public class FileUtils {
 		}
 		return result;
 	}
+	
+	/**
+	 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , ? , *
+	 * @param path
+	 * @return
+	 */
+	public static boolean validatePath(String path) {
+		boolean result = true;
+		
+		Log.d("FileUtils", "path ....... " + path);
+		if (path.contains("\\") || path.contains("<") || path.contains(">") ||
+				path.contains(":") || path.contains("\"") || path.contains("|") || 
+				path.contains("?") || path.contains("*")) {
+			result = false;
+		}
+		return result;
+	}
 }

+ 1 - 2
src/com/owncloud/android/files/services/FileUploader.java

@@ -564,8 +564,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         RemoteOperation operation = new ExistenceCheckOperation(pathToGrant, this, false);
         RemoteOperationResult result = operation.execute(mUploadClient);
         if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) {
-            operation = new CreateFolderOperation(  mCurrentUpload.getFileName(),
-                    pathToGrant,
+            operation = new CreateFolderOperation( pathToGrant,
                     true,
                     mStorageManager    );
             result = operation.execute(mUploadClient);

+ 2 - 5
src/com/owncloud/android/operations/CreateFolderOperation.java

@@ -39,7 +39,6 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
     
     private static final String TAG = CreateFolderOperation.class.getSimpleName();
     
-    protected String mFolderName;
     protected String mRemotePath;
     protected boolean mCreateFullPath;
     protected FileDataStorageManager mStorageManager;
@@ -47,12 +46,10 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
     /**
      * Constructor
      * 
-     * @param remotePath            Full path to the new directory to create in the remote server.
      * @param createFullPath        'True' means that all the ancestor folders should be created if don't exist yet.
      * @param storageManager        Reference to the local database corresponding to the account where the file is contained. 
      */
-    public CreateFolderOperation(String folderName, String remotePath, boolean createFullPath, FileDataStorageManager storageManager) {
-        mFolderName = folderName;
+    public CreateFolderOperation(String remotePath, boolean createFullPath, FileDataStorageManager storageManager) {
         mRemotePath = remotePath;
         mCreateFullPath = createFullPath;
         mStorageManager = storageManager;
@@ -62,7 +59,7 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp
 
     @Override
     protected RemoteOperationResult run(WebdavClient client) {
-        CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mFolderName, mRemotePath, mCreateFullPath);
+        CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath);
         RemoteOperationResult result =  operation.execute(client);
         
         if (result.isSuccess()) {

+ 1 - 1
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1439,7 +1439,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
                 // Create directory
                 path += newDirectoryName + OCFile.PATH_SEPARATOR;
-                RemoteOperation operation = new CreateFolderOperation(newDirectoryName, path, false, mStorageManager);
+                RemoteOperation operation = new CreateFolderOperation(path, false, mStorageManager);
                 operation.execute(  getAccount(), 
                         FileDisplayActivity.this, 
                         FileDisplayActivity.this,