-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b34a41c
commit 73f32fa
Showing
9 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
core-common/src/main/kotlin/com/svenjacobs/app/leon/core/common/url/DecodeUrl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.common.url | ||
|
||
import java.net.URLDecoder | ||
|
||
fun decodeUrl(encoded: String): String = URLDecoder.decode(encoded, "UTF-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...c/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/reddit/RedditMailSanitizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.reddit | ||
|
||
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.common.url.decodeUrl | ||
import com.svenjacobs.app.leon.core.domain.R | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId | ||
|
||
class RedditMailSanitizer : Sanitizer { | ||
|
||
override val id = SanitizerId("reddit_mail") | ||
|
||
override fun getMetadata(context: Context) = Sanitizer.Metadata( | ||
name = context.getString(R.string.sanitizer_reddit_mail), | ||
) | ||
|
||
override fun invoke(input: String): String { | ||
val encoded = URL_REGEX.find(input)?.groupValues?.getOrNull(1) ?: return input | ||
val url = decodeUrl(encoded) | ||
return RegexFactory.AllParameters.replace(url, "") | ||
} | ||
|
||
override fun matchesDomain(input: String) = input.matchesDomain("click.redditmail.com") | ||
|
||
private companion object { | ||
private val URL_REGEX = Regex("click\\.redditmail\\.com/[^/]+/(.+)") | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rc/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/reddit/RedditOutSanitizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.reddit | ||
|
||
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.Sanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SearchResultSanitizer | ||
|
||
class RedditOutSanitizer : SearchResultSanitizer( | ||
RegexFactory.ofParameter("url"), | ||
) { | ||
|
||
override val id = SanitizerId("reddit_out") | ||
|
||
override fun getMetadata(context: Context) = Sanitizer.Metadata( | ||
name = context.getString(R.string.sanitizer_reddit_out), | ||
) | ||
|
||
override fun matchesDomain(input: String) = input.matchesDomain("out.reddit.com") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...st/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/reddit/RedditMailSanitizerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.reddit | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RedditMailSanitizerTest : WordSpec( | ||
{ | ||
val sanitizer = RedditMailSanitizer() | ||
|
||
"invoke" should { | ||
|
||
"extract and decode URL" { | ||
val result = sanitizer( | ||
"https://click.redditmail.com/CL0/https:%2F%2Fwww.reddit.com%2Fr%2FComp" + | ||
"ressOrDie%2Fcomments%2F11u2vso%2Frcompressordie_lounge%2Fjl9fp68%2F%3F\$" + | ||
"deep_link=true%26correlation_id=5329d6c9-34a4-4a44-9cea-76317f68123f%26r" + | ||
"ef=email_comment_reply%26ref_campaign=email_comment_reply%26ref_source=e" + | ||
"mail/3/010001884768a910-4b97a265-36d8-461f-9d79-fc2b535e5217-000000/sa_u" + | ||
"FF6uMCdJu1cTLCaOI8Ng6wQBjfPtc5hMCnOrx4Q=301", | ||
) | ||
|
||
result shouldBe "https://www.reddit.com/r/CompressOrDie/comments/11u2vso/rcompres" + | ||
"sordie_lounge/jl9fp68/" | ||
} | ||
} | ||
|
||
"matchesDomain" should { | ||
|
||
"match for click.redditmail.com" { | ||
sanitizer.matchesDomain("https://click.redditmail.com") shouldBe true | ||
} | ||
} | ||
}, | ||
) |
48 changes: 48 additions & 0 deletions
48
...est/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/reddit/RedditOutSanitizerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.reddit | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RedditOutSanitizerTest : WordSpec( | ||
{ | ||
val sanitizer = RedditOutSanitizer() | ||
|
||
"invoke" should { | ||
|
||
"extract URL" { | ||
val result = sanitizer( | ||
"https://out.reddit.com/t3_11zcpau?url=https%3A%2F%2Fcompress-or-die.co" + | ||
"m%2FThe-nasty-red-JPG-compression-artifacts&token=AQAA-odsZCyQ04Ae10crjv" + | ||
"g8DGlsTPckMpu3vvIjNwmWPgLdQMbC&app_name=web2x&web_redirect=true/", | ||
) | ||
|
||
result shouldBe "https://compress-or-die.com/The-nasty-red-JPG-compression-artifacts" | ||
} | ||
} | ||
|
||
"matchesDomain" should { | ||
|
||
"match for out.reddit.com" { | ||
sanitizer.matchesDomain("https://out.reddit.com") shouldBe true | ||
} | ||
} | ||
}, | ||
) |