fix(autofill): Ignore port during Host match if not specified in the source #629

This commit is contained in:
Artem Chepurnyi 2024-11-01 08:50:53 +02:00
parent 89e77ec65d
commit e29c1d7f3c
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
1 changed files with 10 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import com.artemchep.keyguard.common.io.ioEffect
import com.artemchep.keyguard.common.model.DSecret
import com.artemchep.keyguard.common.service.tld.TldService
import com.artemchep.keyguard.common.usecase.CipherUrlCheck
import io.ktor.http.DEFAULT_PORT
import io.ktor.http.Url
import io.ktor.http.hostWithPort
import org.kodein.di.DirectDI
@ -66,9 +67,15 @@ class CipherUrlCheckImpl(
a: String,
b: String,
): IO<Boolean> = ioEffect {
val aHost = urlOf(a).hostWithPort
val bHost = urlOf(b).hostWithPort
aHost == bHost
val aUrl = urlOf(a)
val bUrl = urlOf(b)
// If the url doesn't have a port specified, then
// match it with any port.
if (aUrl.specifiedPort == DEFAULT_PORT) {
return@ioEffect aUrl.host == bUrl.host
}
aUrl.hostWithPort == bUrl.hostWithPort
}
private fun checkUrlMatchByStartsWith(