Skip to content

Commit

Permalink
feat: add Flipkart sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
svenjacobs committed May 29, 2022
1 parent 6899b90 commit 68e7d7a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.8.0

_2022-05-29_

- Add sanitizer for Flipkart

## Version 0.7.1

_2022-04-10_
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
19 changes: 18 additions & 1 deletion app/src/main/kotlin/com/svenjacobs/app/leon/domain/Defaults.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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_*",
Expand Down Expand Up @@ -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].
*/
Expand All @@ -90,5 +106,6 @@ object Defaults {
Twitter,
Spotify,
Netflix,
Flipkart,
)
}
2 changes: 1 addition & 1 deletion app/src/main/play/release-notes/de-DE/default.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Bugfix: Ankerparameter sollten nicht aus URLs entfernt werden
Reiniger für Flipkart hinzugefügt
2 changes: 1 addition & 1 deletion app/src/main/play/release-notes/en-US/default.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix: don't remove anchors from URLs
Add sanitizer for Flipkart
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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")
}
}
})

0 comments on commit 68e7d7a

Please sign in to comment.