From: David A. Velasco Date: Mon, 18 Nov 2013 13:10:11 +0000 (+0100) Subject: Add check of characters in file name before starting rename/createFolder operations X-Git-Tag: oc-android-1.5.5~126^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/73849d822d10b4037d6f1cf835e0d01ae484740b?ds=inline;hp=-c Add check of characters in file name before starting rename/createFolder operations --- 73849d822d10b4037d6f1cf835e0d01ae484740b diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java index 50f6ce5e..0974d08b 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java +++ b/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)); diff --git a/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java b/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java index e4f10bb5..8fb01dce 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java +++ b/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); diff --git a/res/values/strings.xml b/res/values/strings.xml index 21699cf8..46110933 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -182,7 +182,7 @@ Remote file could not be checked File contents already synchronized Directory could not be created - Invalid character in foldername: / \\ < > : " | ? * + Forbidden characters: / \\ < > : " | ? * Wait a moment "Unexpected problem ; please select the file from a different app" No file was selected diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 37455d2e..685cff24 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/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); diff --git a/src/com/owncloud/android/ui/dialog/EditNameDialog.java b/src/com/owncloud/android/ui/dialog/EditNameDialog.java index 4d6243af..862715fd 100644 --- a/src/com/owncloud/android/ui/dialog/EditNameDialog.java +++ b/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