diff --git a/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt b/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt index bb0b2cd0..96fb5334 100644 --- a/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt +++ b/app/src/main/kotlin/com/svenjacobs/app/leon/startup/ContainerInitializer.kt @@ -48,6 +48,7 @@ import com.svenjacobs.app.leon.core.domain.sanitizer.shopee.ShopeeSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.spiegel.SpiegelSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.spotify.SpotifySanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.theguardian.TheGuardianSanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.threads.ThreadsSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.twitter.TwitterSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.webtrekk.WebtrekkSanitizer import com.svenjacobs.app.leon.core.domain.sanitizer.yahoo.YahooSearchSanitizer @@ -93,6 +94,7 @@ class ContainerInitializer : DistinctInitializer { SpiegelSanitizer(), SpotifySanitizer(), TheGuardianSanitizer(), + ThreadsSanitizer(), TwitterSanitizer(), WebtrekkSanitizer(), YahooSearchSanitizer(), diff --git a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizer.kt b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizer.kt new file mode 100644 index 00000000..f6f29ff6 --- /dev/null +++ b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizer.kt @@ -0,0 +1,40 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2023 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.threads + +import android.content.Context +import com.svenjacobs.app.leon.core.common.domain.matchesDomain +import com.svenjacobs.app.leon.core.common.regex.RegexFactory +import com.svenjacobs.app.leon.core.domain.R +import com.svenjacobs.app.leon.core.domain.sanitizer.RegexSanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer +import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId + +class ThreadsSanitizer : RegexSanitizer( + regex = RegexFactory.AllParameters, +) { + + override val id = SanitizerId("threads") + + override fun getMetadata(context: Context) = Sanitizer.Metadata( + name = context.getString(R.string.sanitizer_threads), + ) + + override fun matchesDomain(input: String) = input.matchesDomain("threads.net") +} diff --git a/core-domain/src/main/res/values/strings.xml b/core-domain/src/main/res/values/strings.xml index 8b7b45dd..4e656832 100644 --- a/core-domain/src/main/res/values/strings.xml +++ b/core-domain/src/main/res/values/strings.xml @@ -45,6 +45,7 @@ Spiegel Spotify The Guardian + Threads.net Twitter Webtrekk Yahoo Search diff --git a/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizerTest.kt b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizerTest.kt new file mode 100644 index 00000000..c7a13c42 --- /dev/null +++ b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/threads/ThreadsSanitizerTest.kt @@ -0,0 +1,44 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2023 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.svenjacobs.app.leon.core.domain.sanitizer.threads + +import io.kotest.core.spec.style.WordSpec +import io.kotest.matchers.shouldBe + +class ThreadsSanitizerTest : WordSpec( + { + val sanitizer = ThreadsSanitizer() + + "invoke" should { + + "remove all parameters" { + sanitizer( + "https://www.threads.net/t/CufR4M8yNdJ/?igshid=NTc4MTIwNjQ2YQ==", + ) shouldBe "https://www.threads.net/t/CufR4M8yNdJ/" + } + } + + "matchesDomain" should { + + "match threads.net" { + sanitizer.matchesDomain("https://threads.net") shouldBe true + } + } + }, +)