From 1d84eaf9c01ceb36ac56870d24bf2f71d5a61d46 Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 20 Sep 2026 23:14:54 +0800 Subject: [PATCH] fix: reject bare .dz source URLs and make extension validation case-insensitive A bare .dz file (DictZip without the .dsl prefix) is treated by the pipeline as an orphaned file and deleted right after the download, so a .dz source URL passed validation but silently produced no dictionary. Accept only DictZip-compressed DSL (.dsl.dz; .gz already covers .dsl.gz) and compare extensions case-insensitively. --- .../example/research/core/domain/model/DictionarySource.kt | 5 ++++- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt b/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt index 7df0ce1..a48d9da 100644 --- a/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt +++ b/app/src/main/java/com/example/research/core/domain/model/DictionarySource.kt @@ -102,12 +102,15 @@ data class DictionarySource( fun validateTemplate(template: String): ValidationResult { val trimmed = template.trim() + val lowerTemplate = trimmed.lowercase() return when { trimmed.isBlank() -> ValidationResult.Error(ValidationError.EMPTY) trimmed.length > 2048 -> ValidationResult.Error(ValidationError.TOO_LONG) !trimmed.startsWith("http://") && !trimmed.startsWith("https://") -> ValidationResult.Error(ValidationError.INVALID_PROTOCOL) - !trimmed.endsWith(".gz") && !trimmed.endsWith(".dsl") && !trimmed.endsWith(".dz") -> + !lowerTemplate.endsWith(".gz") && + !lowerTemplate.endsWith(".dsl") && + !lowerTemplate.endsWith(".dsl.dz") -> ValidationResult.Error(ValidationError.INVALID_EXTENSION) !isValidUrlStructure(trimmed) -> ValidationResult.Error(ValidationError.INVALID_URL_STRUCTURE) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7ab2cce..bd511f0 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -76,7 +76,7 @@ Этот словарь уже существует (одинаковый префикс) URL не может быть пустым Должен начинаться с http:// или https:// - Должен заканчиваться на .gz, .dsl или .dz + Должен заканчиваться на .gz, .dsl или .dsl.dz URL слишком длинный (максимум 2048 символов) Неверный формат URL URL содержит недопустимые символы diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5fd1ba5..2a03b5a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,7 +74,7 @@ This dictionary already exists URL cannot be empty Must start with http:// or https:// - Must end with .gz, .dsl, or .dz + Must end with .gz, .dsl, or .dsl.dz URL is too long (max 2048 characters) Invalid URL format URL contains invalid characters