From e29c1d7f3cb7b136416e9b4737a83c024f7aa934 Mon Sep 17 00:00:00 2001 From: Artem Chepurnyi Date: Fri, 1 Nov 2024 08:50:53 +0200 Subject: [PATCH] fix(autofill): Ignore port during Host match if not specified in the source #629 --- .../provider/bitwarden/usecase/CipherUrlCheck.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/usecase/CipherUrlCheck.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/usecase/CipherUrlCheck.kt index cb9c5cf5..81663372 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/usecase/CipherUrlCheck.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/provider/bitwarden/usecase/CipherUrlCheck.kt @@ -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 = 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(