From 68e7d7ae4ec344ff25650517e64a6dcf522aaf21 Mon Sep 17 00:00:00 2001 From: Sven Jacobs Date: Sun, 29 May 2022 16:16:25 +0200 Subject: [PATCH] feat: add Flipkart sanitizer --- CHANGELOG.md | 12 ++++-- app/build.gradle.kts | 4 +- .../svenjacobs/app/leon/domain/Defaults.kt | 19 ++++++++- .../main/play/release-notes/de-DE/default.txt | 2 +- .../main/play/release-notes/en-US/default.txt | 2 +- .../app/leon/service/FlipkartSanitizerTest.kt | 41 +++++++++++++++++++ 6 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 app/src/test/kotlin/com/svenjacobs/app/leon/service/FlipkartSanitizerTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 79409e6f..ace08740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Version 0.8.0 + +_2022-05-29_ + +- Add sanitizer for Flipkart + ## Version 0.7.1 _2022-04-10_ @@ -17,9 +23,9 @@ _2021-10-20_ - Fix display of title for large fonts (PR #30, thanks @yuhuitech) - Add sanitizers for - - Twitter - - Spotify - - Netflix + - Twitter + - Spotify + - Netflix - Minor UI improvements ## Version 0.5.0 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 51ee256b..a3ec8a28 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -38,8 +38,8 @@ android { applicationId = "com.svenjacobs.app.leon" minSdk = 21 targetSdk = 32 - versionCode = 230 - versionName = "0.7.1" + versionCode = 231 + versionName = "0.8.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/kotlin/com/svenjacobs/app/leon/domain/Defaults.kt b/app/src/main/kotlin/com/svenjacobs/app/leon/domain/Defaults.kt index 210bd145..974688d0 100644 --- a/app/src/main/kotlin/com/svenjacobs/app/leon/domain/Defaults.kt +++ b/app/src/main/kotlin/com/svenjacobs/app/leon/domain/Defaults.kt @@ -1,6 +1,6 @@ /* * Léon - The URL Cleaner - * Copyright (C) 2021 Sven Jacobs + * Copyright (C) 2022 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 @@ -26,6 +26,14 @@ import com.svenjacobs.app.leon.startup.AppInitializer object Defaults { + /** + * This regex matches all parameters of a URL, so everything starting at "?". + * + * Parameters are matched individually instead of just removing everything starting at "?" to + * be able to get a count of removed parameters from the regex result. + */ + private const val ALL_PARAMETERS_REGEX = "(?:\\?|&)[^=]+=[^&]*" + internal val Webtrekk = RegexSanitizer( parameterRegex = regexForWildcardParameter("wt_"), name = "wt_*", @@ -79,6 +87,14 @@ object Defaults { isDefault = true, ) + internal val Flipkart = RegexSanitizer( + domainRegex = "flipkart\\.com", + parameterRegex = ALL_PARAMETERS_REGEX, + name = "flipkart", + description = "Flipkart", + isDefault = true, + ) + /** * List of default [Sanitizer] which are installed during first app start. See [AppInitializer]. */ @@ -90,5 +106,6 @@ object Defaults { Twitter, Spotify, Netflix, + Flipkart, ) } diff --git a/app/src/main/play/release-notes/de-DE/default.txt b/app/src/main/play/release-notes/de-DE/default.txt index 96d97654..d9f3083d 100644 --- a/app/src/main/play/release-notes/de-DE/default.txt +++ b/app/src/main/play/release-notes/de-DE/default.txt @@ -1 +1 @@ -Bugfix: Ankerparameter sollten nicht aus URLs entfernt werden +Reiniger für Flipkart hinzugefügt diff --git a/app/src/main/play/release-notes/en-US/default.txt b/app/src/main/play/release-notes/en-US/default.txt index af81201b..11c87098 100644 --- a/app/src/main/play/release-notes/en-US/default.txt +++ b/app/src/main/play/release-notes/en-US/default.txt @@ -1 +1 @@ -Fix: don't remove anchors from URLs +Add sanitizer for Flipkart diff --git a/app/src/test/kotlin/com/svenjacobs/app/leon/service/FlipkartSanitizerTest.kt b/app/src/test/kotlin/com/svenjacobs/app/leon/service/FlipkartSanitizerTest.kt new file mode 100644 index 00000000..d706ae11 --- /dev/null +++ b/app/src/test/kotlin/com/svenjacobs/app/leon/service/FlipkartSanitizerTest.kt @@ -0,0 +1,41 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2022 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 . + */ + +package com.svenjacobs.app.leon.service + +import com.svenjacobs.app.leon.domain.Defaults.Flipkart +import com.svenjacobs.app.leon.test.MOCK_SANITIZER_STRATEGY_EXECUTOR +import io.kotest.core.spec.style.ShouldSpec +import io.kotest.matchers.be +import io.kotest.matchers.should + +class FlipkartSanitizerTest : ShouldSpec({ + + context("sanitize") { + + should("remove Flipkart parameters") { + val result = MOCK_SANITIZER_STRATEGY_EXECUTOR.sanitize( + Flipkart, + "https://www.flipkart.com/msi-gf63-thin-core-i5-10th-gen-8-gb-512-gb-ssd-windows-10-home-4-graphics-nvidia-geforce-rtx-3050-144-hz-10uc-607in-gaming-laptop/p/itm92565651dc3ed?pid=COMG5AWT9CKRMEFU&lid=LSTCOMG5AWT9CKRMEFULV38QB&marketplace=FLIPKART&q=gaming+laptop&store=6bo%2Fb5g&srno=s_1_15&otracker=AS_QueryStore_OrganicAutoSuggest_1_9_na_na_na&otracker1=AS_QueryStore_OrganicAutoSuggest_1_9_na_na_na&fm=SEARCH&iid=22ff2dee-d44e-40e3-9811-5d229fa974fc.COMG5AWT9CKRMEFU.SEARCH&ppt=hp&ppn=homepage&ssid=zv1f42w4bs3azitc1635436210945&qH=da5ee6f53d84b3c2" + ) + + result.artifactsRemoved should be(14) + result.output should be("https://www.flipkart.com/msi-gf63-thin-core-i5-10th-gen-8-gb-512-gb-ssd-windows-10-home-4-graphics-nvidia-geforce-rtx-3050-144-hz-10uc-607in-gaming-laptop/p/itm92565651dc3ed") + } + } +})