@@ -35,13 +35,19 @@ class DataStoreCookieStorage(private val dataStoreManager: DataStoreManager) : C
35
35
return cookie.expiration.let { System.currentTimeMillis() < it }
36
36
}
37
37
38
- private fun domainMatches(cookieDomain: String, requestHost: String): Boolean {
39
- val cd = cookieDomain.lowercase()
40
- val host = requestHost.lowercase()
41
- return if (cd.startsWith(".")) {
42
- host == cd.substring(1) || host.endsWith(cd)
38
+ private fun domainMatches(cookieDomain: String?, requestHost: String?): Boolean {
39
+ val cd = cookieDomain?.lowercase()
40
+ val host = requestHost?.lowercase()
41
+ return if (cd != null && host != null) {
42
+ if (cd.startsWith(".")) {
43
+ host == cd.substring(1) || host.endsWith(cd)
44
+ } else if (requestHost.startsWith(".")){
45
+ host == host.substring(1) || cd.endsWith(cd)
46
+ } else {
47
+ host == cd
48
+ }
43
49
} else {
44
- host == cd
50
+ false
45
51
}
46
52
}
47
53
@@ -74,7 +80,7 @@ class DataStoreCookieStorage(private val dataStoreManager: DataStoreManager) : C
74
80
val cookies = loadCookies().toMutableList()
75
81
cookies.removeAll { existing ->
76
82
existing.name == newCookie.name &&
77
- existing.domain == newCookie.domain &&
83
+ domainMatches( existing.domain, newCookie.domain) &&
78
84
existing.path == newCookie.path
79
85
}
80
86
cookies.add(newCookie)
0 commit comments