Browse Source

solve git conflict

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 10 months ago
parent
commit
f2f28a0262

+ 17 - 0
app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidationResult.kt

@@ -0,0 +1,17 @@
+/*
+ * Nextcloud - Android Client
+ *
+ * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+package com.nextcloud.utils.fileNameValidator
+
+import com.owncloud.android.R
+
+enum class FileNameValidationResult(val messageId: Int) {
+    EMPTY(R.string.filename_empty),
+    INVALID_CHARACTER(R.string.file_name_validator_error_invalid_character),
+    RESERVED_NAME(R.string.file_name_validator_error_reserved_names),
+    ENDS_WITH_SPACE_OR_PERIOD(R.string.file_name_validator_error_ends_with_space_period)
+}

+ 42 - 0
app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt

@@ -0,0 +1,42 @@
+/*
+ * Nextcloud - Android Client
+ *
+ * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+package com.nextcloud.utils.fileNameValidator
+
+import android.text.TextUtils
+
+object FileNameValidator {
+    private val reservedWindowsChars = "[<>:\"/\\\\|?*]".toRegex()
+    private val reservedWindowsNames = listOf(
+        "CON", "PRN", "AUX", "NUL",
+        "COM0", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
+        "COM¹", "COM²", "COM³",
+        "LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
+        "LPT¹", "LPT²", "LPT³"
+    )
+    private val reservedUnixChars = "[/<>|:&]".toRegex()
+
+    fun isValid(name: String): FileNameValidationResult? {
+        if (name.contains(reservedWindowsChars) || name.contains(reservedUnixChars)) {
+            return FileNameValidationResult.INVALID_CHARACTER
+        }
+
+        if (reservedWindowsNames.contains(name.uppercase())) {
+            return FileNameValidationResult.RESERVED_NAME
+        }
+
+        if (name.endsWith(" ") || name.endsWith(".")) {
+            return FileNameValidationResult.ENDS_WITH_SPACE_OR_PERIOD
+        }
+
+        if (TextUtils.isEmpty(name)) {
+            return FileNameValidationResult.EMPTY
+        }
+
+        return null
+    }
+}

+ 5 - 0
app/src/main/res/values/strings.xml

@@ -1214,7 +1214,12 @@
     <string name="secure_share_not_set_up">Secure sharing is not set up for this user</string>
     <string name="share_not_allowed_when_file_drop">Resharing is not allowed during secure file drop</string>
     <string name="file_list_empty_local_search">No file or folder matching your search</string>
+
     <string name="unified_search_fragment_calendar_event_not_found">Event not found, you can always sync to update. Redirecting to web…</string>
     <string name="unified_search_fragment_contact_not_found">Contact not found, you can always sync to update. Redirecting to web…</string>
     <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_invalid_character">File name contains invalid characters</string>
+    <string name="file_name_validator_error_reserved_names">File name 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>
 </resources>