aboutsummaryrefslogtreecommitdiff
path: root/autofill-parser/src/main/java/com
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-08-24 21:33:29 +0530
committerGitHub <noreply@github.com>2021-08-24 16:03:29 +0000
commit8c56a1d7b84d898714d7ca7d167bd60df033ab57 (patch)
tree043be3fb9bb7e61b0133681ddb400e42173746c2 /autofill-parser/src/main/java/com
parentd59d1770ea6624234d29410a43e299929d18f850 (diff)
Update AndroidX deps (#1491)
Diffstat (limited to 'autofill-parser/src/main/java/com')
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt19
1 files changed, 14 insertions, 5 deletions
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt
index be3cbe66..2a35e8c7 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt
@@ -5,6 +5,8 @@
package com.github.androidpasswordstore.autofillparser
import android.content.Context
+import android.net.InetAddresses
+import android.os.Build
import android.util.Patterns
import kotlinx.coroutines.runBlocking
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
@@ -17,7 +19,7 @@ private object PublicSuffixListCache {
if (!::publicSuffixList.isInitialized) {
publicSuffixList = PublicSuffixList(context)
// Trigger loading the actual public suffix list, but don't block.
- @Suppress("DeferredResultUnused") publicSuffixList.prefetch()
+ @Suppress("DeferredResultUnused") publicSuffixList.prefetchAsync()
}
return publicSuffixList
}
@@ -43,15 +45,21 @@ internal fun getPublicSuffixPlusOne(
// We do not check whether the domain actually exists (actually, not even whether its TLD
// exists). As long as we restrict ourselves to syntactically valid domain names,
// getPublicSuffixPlusOne will return non-colliding results.
- if (!Patterns.DOMAIN_NAME.matcher(domain).matches() ||
- Patterns.IP_ADDRESS.matcher(domain).matches()
- ) {
+ if (!Patterns.DOMAIN_NAME.matcher(domain).matches() || isNumericAddress(domain)) {
domain
} else {
getCanonicalSuffix(context, domain, customSuffixes)
}
}
+private fun isNumericAddress(domain: String): Boolean {
+ return if (Build.VERSION.SDK_INT >= 29) {
+ InetAddresses.isNumericAddress(domain)
+ } else {
+ @Suppress("DEPRECATION") Patterns.IP_ADDRESS.matcher(domain).matches()
+ }
+}
+
/**
* Returns:
* - [domain], if [domain] equals [suffix];
@@ -72,7 +80,8 @@ private suspend fun getCanonicalSuffix(
customSuffixes: Sequence<String>
): String {
val publicSuffixList = PublicSuffixListCache.getOrCachePublicSuffixList(context)
- val publicSuffixPlusOne = publicSuffixList.getPublicSuffixPlusOne(domain).await() ?: return domain
+ val publicSuffixPlusOne =
+ publicSuffixList.getPublicSuffixPlusOneAsync(domain).await() ?: return domain
var longestSuffix = publicSuffixPlusOne
for (customSuffix in customSuffixes) {
val suffixPlusUpToOne = getSuffixPlusUpToOne(domain, customSuffix) ?: continue