Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ internal class OkHttpRegistrableDomainResolver : RegistrableDomainResolver {
val candidate = if ("://" !in hostOrNull) "https://$hostOrNull" else hostOrNull

val url = candidate.toHttpUrlOrNull()
?: "https://${IDN.toASCII(domain)}".toHttpUrlOrNull()
?: domain.idnToAsciiOrNull()?.let { "https://$it".toHttpUrlOrNull() }
?: return null

return url.topPrivateDomain()
}

// IDN throws, rather than returning, on anything DNS cannot hold: a label over 63 characters or,
// on Android, a name too long overall. Free text in a website field reaches here as is.
private fun String.idnToAsciiOrNull(): String? = try {
IDN.toASCII(this)
} catch (_: IllegalArgumentException) {
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ class OkHttpRegistrableDomainResolverTest {
assertEquals(expected = expected, actual = result)
}

@Test
fun `resolves label longer than DNS allows to null`() {
val domain = "a".repeat(64) + ".com"
val expected = null
val result = resolver.resolve(domain)

assertEquals(expected = expected, actual = result)
}

@Test
fun `resolves IPv4 to null`() {
val domain = "127.0.0.1"
Expand Down
Loading