From 1336218c072e25daef8cc2a83e74eb257b1c2577 Mon Sep 17 00:00:00 2001 From: Sven Jacobs Date: Sun, 24 Nov 2024 12:46:11 +0100 Subject: [PATCH] fix: YouTube sanitizer should also clean youtu.be domain (#507) --- .../domain/sanitizer/youtube/YoutubeSanitizer.kt | 2 +- .../domain/sanitizer/youtube/YoutubeSanitizerTest.kt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizer.kt b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizer.kt index c69db7ca..c50d80e3 100644 --- a/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizer.kt +++ b/core-domain/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizer.kt @@ -38,5 +38,5 @@ class YoutubeSanitizer : ) override fun matchesDomain(input: String) = - input.matchesDomainRegex("(?:m(?:usic)?\\.)?youtube\\.com") + input.matchesDomainRegex("(?:(?:(?:m(?:usic)?\\.)?youtube\\.com)|youtu\\.be)") } diff --git a/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizerTest.kt b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizerTest.kt index 488517d5..03b47ac4 100644 --- a/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizerTest.kt +++ b/core-domain/src/test/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/youtube/YoutubeSanitizerTest.kt @@ -33,7 +33,7 @@ class YoutubeSanitizerTest : "https://m.youtube.com/watch?v=CvFH_6DNRCY&pp=ygUHZGVidXNzeQ%3D%3D", ) shouldBe "https://m.youtube.com/watch?v=CvFH_6DNRCY" } - + "remove all parameters except \"t\" from video URLs" { sanitizer( "https://m.youtube.com/watch?v=CvFH_6DNRCY&t=125", @@ -59,6 +59,12 @@ class YoutubeSanitizerTest : ) shouldBe "https://music.youtube.com/watch?v=KGFkMD2zotU" } + + "remove parameters from youtu.be domain" { + sanitizer( + "https://youtu.be/RvRhUHTV_8k?si=OXYBmGTMXib1jlA2?si=UA0UVnrmPbK612Lu", + ) shouldBe "https://youtu.be/RvRhUHTV_8k" + } } "matchesDomain" should { @@ -74,6 +80,10 @@ class YoutubeSanitizerTest : "match music.youtube.com domain" { sanitizer.matchesDomain("https://music.youtube.com/") shouldBe true } + + "match youtu.be domain" { + sanitizer.matchesDomain("https://youtu.be/") shouldBe true + } } }, )