mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 22:25:44 +03:00
Check file names for upload content from other apps
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
63e7c298ca
commit
27774fca78
4 changed files with 24 additions and 4 deletions
|
@ -456,7 +456,7 @@ open class FolderPickerActivity :
|
|||
|
||||
targetFilePaths?.let { filePaths ->
|
||||
if (!isFolderAndFilePathsValid(filePaths)) {
|
||||
DisplayUtils.showSnackMessage(this, R.string.file_name_validator_error_copy_or_move)
|
||||
DisplayUtils.showSnackMessage(this, R.string.file_name_validator_error_contains_reserved_names_or_invalid_characters)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
setResult(RESULT_CANCELED, resultData)
|
||||
finish()
|
||||
|
|
|
@ -671,7 +671,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
|||
|
||||
boolean isPathValid = FileNameValidator.INSTANCE.checkFolderPath(mUploadPath, getCapabilities(), this);
|
||||
if (!isPathValid) {
|
||||
DisplayUtils.showSnackMessage(this, R.string.file_name_validator_error_copy_or_move);
|
||||
DisplayUtils.showSnackMessage(this, R.string.file_name_validator_error_contains_reserved_names_or_invalid_characters);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.net.Uri
|
|||
import android.os.Parcelable
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.jobs.upload.FileUploadHelper
|
||||
import com.nextcloud.utils.fileNameValidator.FileNameValidator
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.files.services.NameCollisionPolicy
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
|
@ -23,6 +24,7 @@ import com.owncloud.android.ui.activity.FileActivity
|
|||
import com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask
|
||||
import com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask.OnCopyTmpFilesTaskListener
|
||||
import com.owncloud.android.ui.fragment.TaskRetainerFragment
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.UriUtils.getDisplayNameForUri
|
||||
|
||||
/**
|
||||
|
@ -70,9 +72,26 @@ class UriUploader(
|
|||
Log_OC.e(TAG, "Sensitive URI detected, aborting upload.")
|
||||
code = UriUploaderResultCode.ERROR_SENSITIVE_PATH
|
||||
} else {
|
||||
val uris = mUrisToUpload.filterNotNull()
|
||||
var isInvalidPathMessageDisplayed = false
|
||||
val uris = mUrisToUpload
|
||||
.filterNotNull()
|
||||
.map { it as Uri }
|
||||
.map { Pair(it, getRemotePathForUri(it)) }
|
||||
.filter { (_, filename) ->
|
||||
val isValid = (FileNameValidator.checkFileName(
|
||||
filename.removePrefix("/"),
|
||||
mActivity.capabilities,
|
||||
mActivity, null
|
||||
) == null)
|
||||
if (!isValid && !isInvalidPathMessageDisplayed) {
|
||||
isInvalidPathMessageDisplayed = true
|
||||
DisplayUtils.showSnackMessage(
|
||||
mActivity,
|
||||
R.string.file_name_validator_upload_content_error
|
||||
)
|
||||
}
|
||||
isValid
|
||||
}
|
||||
|
||||
val fileUris = uris
|
||||
.filter { it.first.scheme == ContentResolver.SCHEME_FILE }
|
||||
|
|
|
@ -1220,7 +1220,8 @@
|
|||
<string name="unified_search_fragment_permission_needed">Permissions are required to open search result otherwise it will redirected to web…</string>
|
||||
|
||||
|
||||
<string name="file_name_validator_error_copy_or_move">Folder path contains reserved names or invalid character</string>
|
||||
<string name="file_name_validator_upload_content_error">Some contents cannot able to uploaded due to contains reserved names or invalid character.</string>
|
||||
<string name="file_name_validator_error_contains_reserved_names_or_invalid_characters">Folder path contains reserved names or invalid character</string>
|
||||
<string name="file_name_validator_error_invalid_character">File name contains invalid characters: %s</string>
|
||||
<string name="file_name_validator_error_reserved_names">%s is a reserved name</string>
|
||||
<string name="file_name_validator_error_ends_with_space_period">File name ends with a space or a period</string>
|
||||
|
|
Loading…
Reference in a new issue