Skip to content

Commit

Permalink
Add Google Play Store sanitizer as per #308 (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbreuer authored Oct 24, 2024
1 parent b4bf274 commit 95d2d27
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.google.GoogleStoreSanitizer
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
Expand Down Expand Up @@ -93,6 +94,7 @@ class ContainerInitializer : DistinctInitializer<Unit> {
GoogleAdsSanitizer(),
GoogleAnalyticsSanitizer(),
GoogleSearchSanitizer(),
GoogleStoreSanitizer(),
HeiseSanitizer(),
InstagramSanitizer(),
JdoqocySanitizer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.google

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 GoogleStoreSanitizer :
RegexSanitizer(
RegexFactory.ofParameter("hl|selections"),
) {

override val id = SanitizerId("google_play_store")

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

override fun matchesDomain(input: String) = input.matchesDomain("store.google.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 @@ -34,6 +34,7 @@
<string name="sanitizer_ga_name" translatable="false">Google Analytics</string>
<string name="sanitizer_georiot_name" translatable="false">GeoRiot</string>
<string name="sanitizer_google_ads_name" translatable="false">Google Ads</string>
<string name="sanitizer_google_play_store_name" translatable="false">Google Play Store</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>
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.google

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

class GoogleStoreSanitizerTest :
WordSpec(
{

val sanitizer = GoogleStoreSanitizer()

"invoke" should {

"remove \"hl\" and \"selections\" parameters" {
val result = sanitizer(
"https://store.google.com/gb/product/chromecast_google_tv?hl=en-GB" +
"&selections=eyJwcm9kdWN0RmFtaWx5IjoiWTJoeWIyMWxZMkZ6ZEY5bmIyOW5iR1" +
"ZmZEhZPSIsImhlcm9Qcm9kdWN0cyI6W1siY0hKa1h6YzRNekpmTXprMU1nPT0iLDEs" +
"bnVsbF1dfQ%3D%3D",
)

result shouldBe "https://store.google.com/gb/product/chromecast_google_tv"
}
}
},
)

0 comments on commit 95d2d27

Please sign in to comment.