Skip to content

Commit

Permalink
Merge pull request #38 from privy-open-source/fix/allow-redirection
Browse files Browse the repository at this point in the history
release: `1.1.0`
  • Loading branch information
adenvt authored Oct 4, 2024
2 parents 867da12 + 63035f5 commit 76a478a
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ allprojects {
2. Add the dependency
```gradle
dependencies {
implementation 'dev.privyid:pena-android:1.0.0'
implementation 'dev.privyid:pena-android:1.1.0'
}
```

Expand Down
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jdk:
- openjdk11
- openjdk20
before_install:
- ./scripts/prepareJitpackEnvironment.sh
2 changes: 1 addition & 1 deletion pena/src/main/java/dev/privyid/pena/Pena.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Pena : WebView {

this.settings.domStorageEnabled = true
this.settings.javaScriptEnabled = true
this.webViewClient = PenaWebClient(url)
this.webViewClient = PenaWebClient()
this.addJavascriptInterface(this.bridge, "PenaAndroid")

this.loadUrl(
Expand Down
12 changes: 2 additions & 10 deletions pena/src/main/java/dev/privyid/pena/PenaWebClient.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package dev.privyid.pena

import android.net.Uri
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient

class PenaWebClient(url: String) : WebViewClient() {
private var url: Uri = Uri.parse(url)

class PenaWebClient() : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
if (request != null) {
if (isSameDomain(this.url, request.url))
return false
}

return true
return request == null || (request.url.scheme != "http" && request.url.scheme != "https")
}
}
14 changes: 0 additions & 14 deletions pena/src/main/java/dev/privyid/pena/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,4 @@ fun createURL(
}

return uri.build().toString()
}

fun extractDomain(url: Uri): String? {
val host = url.host
val pattern = Regex("""(?:.*\.)?([^.]+\.[^.]+)$""")

return host?.let { pattern.find(it)?.groupValues?.get(1) }
}

fun isSameDomain(a: Uri, b: Uri): Boolean {
val domainA = extractDomain(a)
val domainB = extractDomain(b)

return domainA != null && domainB != null && domainA == domainB
}
13 changes: 7 additions & 6 deletions pena/src/test/java/dev/privyid/pena/UtilsUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.privyid.pena

import android.net.Uri
import org.junit.Test
import org.junit.Assert.*
import org.junit.runner.RunWith
Expand All @@ -8,42 +9,42 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class UtilsUnitTest {
@Test
fun createURL_basic () {
fun createURL_basic() {
val result = createURL(url = "http://coba.com")

assertEquals(result, "http://coba.com")
}

@Test
fun createURL_lang () {
fun createURL_lang() {
val result = createURL(url = "http://coba.com", lang = "id")

assertEquals(result, "http://coba.com?lang=id")
}

@Test
fun createURL_debug () {
fun createURL_debug() {
val result = createURL(url = "http://coba.com", debug = true)

assertEquals(result, "http://coba.com?debug=true")
}

@Test
fun createURL_visibility () {
fun createURL_visibility() {
val result = createURL(url = "http://coba.com", visibility = false)

assertEquals(result, "http://coba.com?visibility=false")
}

@Test
fun createURL_needScrollTo_number () {
fun createURL_needScrollTo_number() {
val result = createURL(url = "http://coba.com", needScrollTo = 5)

assertEquals(result, "http://coba.com?need_scrollto=5")
}

@Test
fun createURL_needScrollTo_string () {
fun createURL_needScrollTo_string() {
val result = createURL(url = "http://coba.com", needScrollTo = "last")

assertEquals(result, "http://coba.com?need_scrollto=last")
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ pluginManagement {
gradlePluginPortal()
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
Expand Down

0 comments on commit 76a478a

Please sign in to comment.