Skip to content

Commit

Permalink
Remove tracking parameters from Spiegel.de URLs (#146)
Browse files Browse the repository at this point in the history
* Add Spiegel Sanitizer

Removes all parameters from Spiegel.de URLs, as they use sara tracking parameters, see #139

* Register Spiegel sanitizer in startup

* Add Spiegel translation

* Create SpiegelSanitizerTest.kt

* Rename and move SpiegelSanitizer

* Update SpiegelSanitizerTest.kt

* Fix linting

* Fix linting
  • Loading branch information
guerda authored Jan 6, 2023
1 parent 83bad50 commit 354723d
Show file tree
Hide file tree
Showing 4 changed files with 91 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.linksynergy.LinkSynergySani
import com.svenjacobs.app.leon.core.domain.sanitizer.netflix.NetflixSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.newegg.NewEggSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.sessionids.SessionIdsSanitizer
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.twitter.TwitterSanitizer
import com.svenjacobs.app.leon.core.domain.sanitizer.webtrekk.WebtrekkSanitizer
Expand Down Expand Up @@ -73,6 +74,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
NetflixSanitizer(),
NewEggSanitizer(),
SessionIdsSanitizer(),
SpiegelSanitizer(),
SpotifySanitizer(),
TwitterSanitizer(),
WebtrekkSanitizer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.spiegel

import android.content.Context
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 SpiegelSanitizer : RegexSanitizer(
regex = RegexFactory.AllParameters,
) {

override val id = SanitizerId("spiegel")

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

override fun matchesDomain(input: String) = DOMAIN_REGEX.containsMatchIn(
input,
)

private companion object {
private val DOMAIN_REGEX = Regex("spiegel\\.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_netflix_name" translatable="false">Netflix</string>
<string name="sanitizer_newegg_name" translatable="false">NewEgg</string>
<string name="sanitizer_session_ids_name" translatable="false">Session IDs</string>
<string name="sanitizer_spiegel_name" translatable="false">Spiegel</string>
<string name="sanitizer_spotify_name" translatable="false">Spotify</string>
<string name="sanitizer_twitter_name" translatable="false">Twitter</string>
<string name="sanitizer_webtrekk_name" translatable="false">Webtrekk</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.spiegel

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

class SpiegelSanitizerTest : WordSpec(
{

"invoke" should {

"remove all parameters from Spiegel URL" {
val sanitizer = SpiegelSanitizer()
val result = sanitizer(
"https://www.spiegel.de/netzwelt/elon-musk-twitter-sperrt-konten-mehrerer" +
"-journalisten-von-new-york-times-washington-post-etc-a-040213a0-aa1e-4" +
"627-9a5a-69d5f4f929fb?sara_ecid=soci_upd_KsBF0AFjflf0DZCxpPYDCQgO1dEMph1",
)

result shouldBe "https://www.spiegel.de/netzwelt/elon-musk-twitter-sperrt-k" +
"onten-mehrerer-journalisten-von-new-york-times-washington-post-etc-a-0" +
"40213a0-aa1e-4627-9a5a-69d5f4f929fb"
}
}
},
)

0 comments on commit 354723d

Please sign in to comment.