diff --git a/app/src/androidTest/java/com/nextcloud/utils/FileNameValidatorTests.kt b/app/src/androidTest/java/com/nextcloud/utils/FileNameValidatorTests.kt index e457514516..881c96ae53 100644 --- a/app/src/androidTest/java/com/nextcloud/utils/FileNameValidatorTests.kt +++ b/app/src/androidTest/java/com/nextcloud/utils/FileNameValidatorTests.kt @@ -55,31 +55,39 @@ class FileNameValidatorTests : AbstractOnServerIT() { testOnlyOnServer(NextcloudVersion.nextcloud_30) val result = FileNameValidator.checkFileName("CON", capability, targetContext) - assertEquals(targetContext.getString(R.string.file_name_validator_error_reserved_names, "CON"), result) + assertEquals(targetContext.getString(R.string.file_name_validator_error_reserved_names, "con"), result) } @Test fun testForbiddenFilenameExtension() { testOnlyOnServer(NextcloudVersion.nextcloud_30) - val result = FileNameValidator.checkFileName("my_fav_file.filepart", capability, targetContext) + val result = FileNameValidator.checkFileName("my_fav_file.part", capability, targetContext) assertEquals( - targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, "filepart"), + targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, ".part"), result ) } @Test fun testEndsWithSpaceOrPeriod() { - val result = FileNameValidator.checkFileName("filename ", capability, targetContext) - val result2 = FileNameValidator.checkFileName("filename.", capability, targetContext) + val firstFilename = "test " + val secondFilename = "test." + val result = FileNameValidator.checkFileName(firstFilename, capability, targetContext) + val result2 = FileNameValidator.checkFileName(secondFilename, capability, targetContext) if (capability.version.isOlderThan(NextcloudVersion.nextcloud_30)) { assertEquals(null, result) assertEquals(null, result2) } else { - assertEquals(targetContext.getString(R.string.file_name_validator_error_ends_with_space_period), result) - assertEquals(targetContext.getString(R.string.file_name_validator_error_ends_with_space_period), result2) + assertEquals( + targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, " "), + result + ) + assertEquals( + targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, "."), + result2 + ) } } diff --git a/app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt b/app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt index c36c3ec412..ac738ce371 100644 --- a/app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt +++ b/app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt @@ -60,33 +60,37 @@ object FileNameValidator { forbiddenFilenameBaseNames().let { val forbiddenBaseNames = forbiddenFilenameBaseNames().map { it.lowercase() } - if (forbiddenBaseNames.any { it in filenameVariants }) { - return context.getString( - R.string.file_name_validator_error_reserved_names, - filename.substringBefore(StringConstants.DOT) - ) + for (forbiddenBaseName in forbiddenBaseNames) { + if (forbiddenBaseName in filenameVariants) { + return context.getString( + R.string.file_name_validator_error_reserved_names, + forbiddenBaseName + ) + } } } forbiddenFilenamesJson?.let { val forbiddenFilenames = forbiddenFilenames().map { it.lowercase() } - if (forbiddenFilenames.any { it in filenameVariants }) { - return context.getString( - R.string.file_name_validator_error_reserved_names, - filename.substringBefore(StringConstants.DOT) - ) + for (forbiddenFilename in forbiddenFilenames) { + if (forbiddenFilename in filenameVariants) { + return context.getString( + R.string.file_name_validator_error_reserved_names, + forbiddenFilename + ) + } } } forbiddenFilenameExtensionJson?.let { - val forbiddenExtensions = forbiddenFilenameExtension() - - if (forbiddenExtensions.any { filename.endsWith(it, ignoreCase = true) }) { - return context.getString( - R.string.file_name_validator_error_forbidden_file_extensions, - filename.substringAfter(StringConstants.DOT) - ) + for (forbiddenExtension in forbiddenFilenameExtension()) { + if (filename.endsWith(forbiddenExtension, ignoreCase = true)) { + return context.getString( + R.string.file_name_validator_error_forbidden_file_extensions, + forbiddenExtension + ) + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e4e775f10..c8f66835fe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1241,7 +1241,7 @@ Folder path contains reserved names or invalid character Name contains an invalid character: %s %s is a forbidden name - .%s is a forbidden file extension + %s is a forbidden file extension Name ends with a space or a period Sync