Skip to content

Commit

Permalink
feat: Add sanitizer for The Guardian (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs authored May 22, 2023
1 parent 7b20f4b commit 701d285
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.svenjacobs.app.leon.core.domain.sanitizer.sessionids.SessionIdsSaniti
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.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 @@ -86,6 +87,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
ShopeeSanitizer(),
SpiegelSanitizer(),
SpotifySanitizer(),
TheGuardianSanitizer(),
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.theguardian

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 TheGuardianSanitizer : RegexSanitizer(
regex = RegexFactory.AllParameters,
) {

override val id = SanitizerId("theguardian")

override fun getMetadata(context: Context) = Sanitizer.Metadata(
name = context.getString(R.string.sanitizer_theguardian),
)

override fun matchesDomain(input: String) = input.matchesDomain("theguardian.com")
}
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 @@ -48,4 +48,5 @@
<string name="sanitizer_lazada" translatable="false">Lazada</string>
<string name="sanitizer_shopee" translatable="false">Shopee</string>
<string name="sanitizer_pearl" translatable="false">Pearl</string>
<string name="sanitizer_theguardian" translatable="false">The Guardian</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.theguardian

import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe

class TheGuardianSanitizerTest : WordSpec(
{
val sanitizer = TheGuardianSanitizer()

"invoke" should {

"remove all parameters" {

val result = sanitizer(
"https://www.theguardian.com/world/2023/jan/15/nepal-plane-crash-with-7" +
"2-onboard-leaves-at-least-16-dead?CMP=Share_AndroidApp_Other",
)

result shouldBe "https://www.theguardian.com/world/2023/jan/15/nepal-plane-crash-" +
"with-72-onboard-leaves-at-least-16-dead"
}
}

"matchesDomain" should {

"match for theguardian.com" {
sanitizer.matchesDomain("https://www.theguardian.com") shouldBe true
}
}
},
)

0 comments on commit 701d285

Please sign in to comment.