mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-30 01:48:14 +00:00 
			
		
		
		
	Filter only '/' character in user input when version of server is 8.1 or later
This commit is contained in:
		
							parent
							
								
									e48aa9c304
								
							
						
					
					
						commit
						9fc332eef9
					
				| @ -51,6 +51,7 @@ import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonym | ||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| public class OwnCloudClient extends HttpClient { | ||||
| 	 | ||||
| @ -68,6 +69,8 @@ public class OwnCloudClient extends HttpClient { | ||||
|      | ||||
|     private Uri mBaseUri; | ||||
| 
 | ||||
|     private OwnCloudVersion mVersion = null; | ||||
|      | ||||
|     /** | ||||
|      * Constructor | ||||
|      */ | ||||
| @ -436,4 +439,12 @@ public class OwnCloudClient extends HttpClient { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public void setOwnCloudVersion(String version){ | ||||
|         OwnCloudVersion ver = new OwnCloudVersion(version); | ||||
|         mVersion = ver; | ||||
|     } | ||||
| 
 | ||||
|     public OwnCloudVersion getOwnCloudVersion(){ | ||||
|         return mVersion; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -24,7 +24,6 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.resources.files; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.HttpStatus; | ||||
| import org.apache.jackrabbit.webdav.client.methods.MkColMethod; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| @ -73,7 +72,8 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mRemotePath); | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, | ||||
|                 client.getOwnCloudVersion().isVersionWithForbiddenCharacters()); | ||||
|         if (noInvalidChars) { | ||||
|         	result = createFolder(client); | ||||
|     		if (!result.isSuccess() && mCreateFullPath &&  | ||||
|  | ||||
| @ -27,9 +27,12 @@ package com.owncloud.android.lib.resources.files; | ||||
| import java.io.File; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| public class FileUtils { | ||||
| 
 | ||||
| 	private static final  String TAG = FileUtils.class.getSimpleName(); | ||||
| 
 | ||||
| 	public static final String PATH_SEPARATOR = "/"; | ||||
| 
 | ||||
| 
 | ||||
| @ -40,39 +43,44 @@ public class FileUtils { | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , * | ||||
| 	 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , | ||||
| 	 * : , " , | , ? , * | ||||
| 	 * @param fileName | ||||
| 	 * @param versionSupportsForbiddenChars | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	public static boolean isValidName(String fileName) { | ||||
| 	public static boolean isValidName(String fileName, boolean versionSupportsForbiddenChars) { | ||||
| 		boolean result = true; | ||||
| 		 | ||||
| 		Log_OC.d("FileUtils", "fileName =======" + fileName); | ||||
| 		if (fileName.contains(PATH_SEPARATOR) || | ||||
| 		Log_OC.d(TAG, "fileName =======" + fileName); | ||||
| 		if ( (versionSupportsForbiddenChars && fileName.contains(PATH_SEPARATOR)) || | ||||
| 				(!versionSupportsForbiddenChars && ( fileName.contains(PATH_SEPARATOR) || | ||||
| 				fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") || | ||||
| 				fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") || | ||||
| 				fileName.contains("?") || fileName.contains("*")) { | ||||
| 				fileName.contains("?") || fileName.contains("*") ) ) ) { | ||||
| 
 | ||||
| 			result = false; | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , ? , * | ||||
| 	 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , | ||||
| 	 * ? , * | ||||
| 	 * @param path | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	public static boolean isValidPath(String path) { | ||||
| 	public static boolean isValidPath(String path, boolean versionSupportsForbidenChars) { | ||||
| 		boolean result = true; | ||||
| 		 | ||||
| 		Log_OC.d("FileUtils", "path ....... " + path); | ||||
| 		if (path.contains("\\") || path.contains("<") || path.contains(">") || | ||||
| 		Log_OC.d(TAG, "path ....... " + path); | ||||
| 		if (!versionSupportsForbidenChars && | ||||
| 				(path.contains("\\") || path.contains("<") || path.contains(">") || | ||||
| 				path.contains(":") || path.contains("\"") || path.contains("|") ||  | ||||
| 				path.contains("?") || path.contains("*")) { | ||||
| 				path.contains("?") || path.contains("*") ) ){ | ||||
| 			result = false; | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -89,7 +89,8 @@ public class MoveRemoteFileOperation extends RemoteOperation { | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		 | ||||
|     	/// check parameters | ||||
|         if (!FileUtils.isValidPath(mTargetRemotePath)) { | ||||
|         if (!FileUtils.isValidPath(mTargetRemotePath, | ||||
|                 client.getOwnCloudVersion().isVersionWithForbiddenCharacters())) { | ||||
|         	return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|         } | ||||
|          | ||||
|  | ||||
| @ -89,7 +89,8 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
| 		 | ||||
| 		LocalMoveMethod move = null; | ||||
|          | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath); | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath, | ||||
|                 client.getOwnCloudVersion().isVersionWithForbiddenCharacters()); | ||||
|          | ||||
|         if (noInvalidChars) { | ||||
|         try { | ||||
|  | ||||
| @ -39,6 +39,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|      | ||||
|     public static final int MINIMUM_VERSION_FOR_SHARING_API = 0x05001B00; // 5.0.27 | ||||
| 
 | ||||
|     public static final int MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000; // 8.1 | ||||
|      | ||||
|     private static final int MAX_DOTS = 3; | ||||
|      | ||||
|     // format is in version | ||||
| @ -121,5 +123,9 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|     	return (mVersion >= MINIMUM_VERSION_FOR_SHARING_API); | ||||
|     } | ||||
| 
 | ||||
|     public boolean isVersionWithForbiddenCharacters() { | ||||
|         return (mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS); | ||||
|     } | ||||
|      | ||||
|      | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user