Эх сурвалжийг харах

Add check of characters in file name before starting rename/createFolder operations

David A. Velasco 11 жил өмнө
parent
commit
73849d822d

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

@@ -53,7 +53,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
-        boolean noInvalidChars = FileUtils.validatePath(mRemotePath);
+        boolean noInvalidChars = FileUtils.isValidPath(mRemotePath);
         if (noInvalidChars) {
         	try {
         		mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));

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

@@ -20,7 +20,7 @@ public class FileUtils {
 	 * @param fileName
 	 * @return
 	 */
-	public static boolean validateName(String fileName) {
+	public static boolean isValidName(String fileName) {
 		boolean result = true;
 		
 		Log.d("FileUtils", "fileName =======" + fileName);
@@ -38,7 +38,7 @@ public class FileUtils {
 	 * @param path
 	 * @return
 	 */
-	public static boolean validatePath(String path) {
+	public static boolean isValidPath(String path) {
 		boolean result = true;
 		
 		Log.d("FileUtils", "path ....... " + path);

+ 1 - 1
res/values/strings.xml

@@ -182,7 +182,7 @@
     <string name="sync_file_fail_msg">Remote file could not be checked</string>
     <string name="sync_file_nothing_to_do_msg">File contents already synchronized</string>
     <string name="create_dir_fail_msg">Directory could not be created</string>
-    <string name="create_dir_fail_msg_invalid_characters">Invalid character in foldername: /  \\  &lt;  &gt;  :  "  |  ?  *</string>
+    <string name="filename_forbidden_characters">Forbidden characters: / \\ &lt; &gt; : " | ? *</string>
     <string name="wait_a_moment">Wait a moment</string>
     <string name="filedisplay_unexpected_bad_get_content">"Unexpected problem ; please select the file from a different app"</string>
     <string name="filedisplay_no_file_selected">No file was selected</string>

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

@@ -1335,7 +1335,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         } else {
             dismissLoadingDialog();
             if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
-                Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG).show();
+                Toast.makeText(FileDisplayActivity.this, R.string.filename_forbidden_characters, Toast.LENGTH_LONG).show();
             } else {
             try {
                 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); 

+ 6 - 1
src/com/owncloud/android/ui/dialog/EditNameDialog.java

@@ -27,10 +27,11 @@ import android.view.View;
 import android.view.WindowManager.LayoutParams;
 import android.widget.EditText;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.actionbarsherlock.app.SherlockDialogFragment;
 import com.owncloud.android.R;
-
+import com.owncloud.android.oc_framework.utils.FileUtils;
 
 
 /**
@@ -129,6 +130,10 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte
         switch (which) {
             case AlertDialog.BUTTON_POSITIVE: {
                 mNewFilename = ((TextView)(getDialog().findViewById(R.id.user_input))).getText().toString();
+                if (!FileUtils.isValidName(mNewFilename)) {
+                    Toast.makeText(getSherlockActivity(), R.string.filename_forbidden_characters, Toast.LENGTH_LONG).show();
+                    return;
+                }
                 mResult = true;
             }
             case AlertDialog.BUTTON_NEGATIVE: { // fall through