Skip to content

Commit

Permalink
Update play store URL regex and related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
theapache64 committed Jan 19, 2025
1 parent 1abb920 commit 30fd907
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class AppListViewModel @Inject constructor(


private val playStoreUrlRegEx by lazy {
"^https:\\/\\/play\\.google\\.com\\/store\\/apps\\/details\\?id=(?<packageName>[\\w\\.]+)\$".toRegex()
"^https:\\/\\/play\\.google\\.com\\/store\\/apps\\/details\\?id=(?<packageName>[\\w\\.]+)(&.+)*\$".toRegex()
}

fun isPlayStoreUrl(input: String): Boolean {
return playStoreUrlRegEx.matches(input)
return playStoreUrlRegEx.containsMatchIn(input)
}

fun parsePackageName(playStoreUrl: String): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class AppListViewModelTest {
).should.`true`
}

@Test
fun validFullUrl() {
AppListViewModel.isPlayStoreUrl(
"https://play.google.com/store/apps/details?id=in.startv.hotstar&hl=en_IN"
).should.`true`
}

@Test
fun invalidUrl() {
AppListViewModel.isPlayStoreUrl(
Expand All @@ -25,6 +32,13 @@ class AppListViewModelTest {
).should.equal("com.theapache64.papercop")
}

@Test
fun parseValidPackageNameFull() {
AppListViewModel.parsePackageName(
"https://play.google.com/store/apps/details?id=com.theapache64.papercop&hl=en_IN"
).should.equal("com.theapache64.papercop")
}

@Test
fun parseInvalidPackageName() {
AppListViewModel.parsePackageName(
Expand Down

0 comments on commit 30fd907

Please sign in to comment.