Skip to content

Commit

Permalink
feat: Add sanitizer for heise.de (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs authored Oct 4, 2023
1 parent ce0776b commit b4506de
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.svenjacobs.app.leon.core.domain.sanitizer.georiot.GeoRiotSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.google.GoogleAdsSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.google.GoogleAnalyticsSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.google.GoogleSearchSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.heise.HeiseSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.instagram.InstagramSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.jdoqocy.JdoqocySanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.lazada.LazadaSanitizer
Expand Down Expand Up @@ -90,6 +91,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
GoogleAdsSanitizer(),
GoogleAnalyticsSanitizer(),
GoogleSearchSanitizer(),
HeiseSanitizer(),
InstagramSanitizer(),
JdoqocySanitizer(),
LazadaSanitizer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.heise

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 HeiseSanitizer : RegexSanitizer(
RegexFactory.AllParameters,
) {
override val id = SanitizerId("heise")

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

override fun matchesDomain(input: String) = input.matchesDomain("heise.de")
}
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 @@ -35,6 +35,7 @@
<string name="sanitizer_georiot_name" translatable="false">GeoRiot</string>
<string name="sanitizer_google_ads_name" translatable="false">Google Ads</string>
<string name="sanitizer_google_search_name">Google Search</string>
<string name="sanitizer_heise" translatable="false">heise online</string>
<string name="sanitizer_instagram_name" translatable="false">Instagram</string>
<string name="sanitizer_jdoqocy_name" translatable="false">Jdoqocy</string>
<string name="sanitizer_lazada" translatable="false">Lazada</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.heise

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

class HeiseSanitizerTest : WordSpec(
{
val sanitizer = HeiseSanitizer()

"invoke" should {

"clean heise.de URLs" {
sanitizer.invoke(
"https://www.heise.de/news/Boom-bei-Balkonkraftwerken-Bereits-mehr-als-" +
"300-000-in-Betrieb-9324094.html?wt_mc=rss.red.ho.ho.rdf.beitrag.beitrag",
) shouldBe "https://www.heise.de/news/Boom-bei-Balkonkraftwerken-Bereits-mehr-als" +
"-300-000-in-Betrieb-9324094.html"
}
}

"matchesDomain" should {

"match heise.de" {
sanitizer.matchesDomain("https://heise.de") shouldBe true
}
}
},
)

0 comments on commit b4506de

Please sign in to comment.