diff --git a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt index 9cda1f5746..de4e5a6842 100644 --- a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt +++ b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt @@ -109,6 +109,27 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/" getTestTranslation(namespace = "test").assert.isNotNull } + @Test + @ProjectJWTAuthTestMethod + fun `maps null namespace from non-null mapping`() { + val fileName = "guessed-ns/en.json" + performImport( + projectId = testData.project.id, + listOf(Pair(fileName, simpleJson)), + getFileMappings(fileName, namespace = null), + ).andIsOk + + getTestTranslation().assert.isNotNull + + performImport( + projectId = testData.project.id, + listOf(Pair(fileName, simpleJson)), + mapOf(), + ).andIsOk + + getTestTranslation(namespace = "guessed-ns").assert.isNotNull + } + @Test @ProjectJWTAuthTestMethod fun `respects provided format`() { diff --git a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/CoreImportFilesProcessor.kt b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/CoreImportFilesProcessor.kt index 089ab23e9c..0b2de76c6c 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/CoreImportFilesProcessor.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/CoreImportFilesProcessor.kt @@ -156,7 +156,7 @@ class CoreImportFilesProcessor( val mappedNamespace = findMappedNamespace() if (mappedNamespace != null) { - return mappedNamespace + return getSafeNamespace(mappedNamespace) } if (this.namespace != null) { @@ -174,6 +174,12 @@ class CoreImportFilesProcessor( } private fun FileProcessorContext.findMappedNamespace(): String? { + if (mapping != null) { + // if mapping is present, use it even when the namespace is null to avoid + // guessing from the file name + return this.mapping?.namespace ?: "" + } + return this.mapping?.namespace }