Skip to content

Commit

Permalink
feat: Add Threads.net sanitizer (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs authored Jul 10, 2023
1 parent 306e514 commit e9a2f82
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,6 +94,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
SpiegelSanitizer(),
SpotifySanitizer(),
TheGuardianSanitizer(),
ThreadsSanitizer(),
TwitterSanitizer(),
WebtrekkSanitizer(),
YahooSearchSanitizer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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")
}
1 change: 1 addition & 0 deletions core-domain/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="sanitizer_spiegel_name" translatable="false">Spiegel</string>
<string name="sanitizer_spotify_name" translatable="false">Spotify</string>
<string name="sanitizer_theguardian" translatable="false">The Guardian</string>
<string name="sanitizer_threads" translatable="false">Threads.net</string>
<string name="sanitizer_twitter_name" translatable="false">Twitter</string>
<string name="sanitizer_webtrekk_name" translatable="false">Webtrekk</string>
<string name="sanitizer_yahoo_search_name">Yahoo Search</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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
}
}
},
)

0 comments on commit e9a2f82

Please sign in to comment.