Add check of characters in file name before starting rename/createFolder operations
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 18 Nov 2013 13:10:11 +0000 (14:10 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 18 Nov 2013 13:10:11 +0000 (14:10 +0100)
oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java
oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java
res/values/strings.xml
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/dialog/EditNameDialog.java

index 50f6ce5..0974d08 100644 (file)
@@ -53,7 +53,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
         RemoteOperationResult result = null;
         MkColMethod mkcol = null;
         
         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));
         if (noInvalidChars) {
                try {
                        mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
index e4f10bb..8fb01dc 100644 (file)
@@ -20,7 +20,7 @@ public class FileUtils {
         * @param fileName
         * @return
         */
         * @param fileName
         * @return
         */
-       public static boolean validateName(String fileName) {
+       public static boolean isValidName(String fileName) {
                boolean result = true;
                
                Log.d("FileUtils", "fileName =======" + fileName);
                boolean result = true;
                
                Log.d("FileUtils", "fileName =======" + fileName);
@@ -38,7 +38,7 @@ public class FileUtils {
         * @param path
         * @return
         */
         * @param path
         * @return
         */
-       public static boolean validatePath(String path) {
+       public static boolean isValidPath(String path) {
                boolean result = true;
                
                Log.d("FileUtils", "path ....... " + path);
                boolean result = true;
                
                Log.d("FileUtils", "path ....... " + path);
index 21699cf..4611093 100644 (file)
     <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="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>
     <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>
index 37455d2..685cff2 100644 (file)
@@ -1335,7 +1335,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         } else {
             dismissLoadingDialog();
             if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
         } 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); 
             } else {
             try {
                 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); 
index 4d6243a..862715f 100644 (file)
@@ -27,10 +27,11 @@ import android.view.View;
 import android.view.WindowManager.LayoutParams;
 import android.widget.EditText;
 import android.widget.TextView;
 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.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();
         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
                 mResult = true;
             }
             case AlertDialog.BUTTON_NEGATIVE: { // fall through