fix host contains incorrect url schema part

This commit is contained in:
tateisu 2021-02-05 08:51:45 +09:00
parent 4cf16c6ee8
commit 11ab61ca7f
2 changed files with 11 additions and 5 deletions

View File

@ -5,6 +5,10 @@ import java.net.IDN
import java.util.*
import java.util.concurrent.ConcurrentHashMap
private val reUrlSchema = """\A\w+://""".toRegex()
fun String.removeUrlSchema() = replace(reUrlSchema,"")
class Host private constructor(
val ascii : String,
val pretty : String = ascii
@ -33,14 +37,16 @@ class Host private constructor(
companion object {
// declare this first!
private val hostSet = ConcurrentHashMap<String, Host>()
val EMPTY = Host("")
val UNKNOWN = Host("?")
val FRIENDS_NICO = Host("friends.nico")
fun parse(src : String) : Host {
val cached = hostSet[src]
fun parse(srcArg : String) : Host {
val cached = hostSet[srcArg]
if(cached != null) return cached
val src = srcArg.removeUrlSchema()
val ascii = IDN.toASCII(src, IDN.ALLOW_UNASSIGNED).toLowerCase(Locale.JAPAN)
val pretty = IDN.toUnicode(src, IDN.ALLOW_UNASSIGNED)
val host = if(ascii == pretty) Host(ascii) else Host(ascii, pretty)

View File

@ -84,7 +84,7 @@ class SavedAccount(
this.apiHost = tmpApiHost ?: tmpApDomain ?: tmpAcct.host ?: error("missing apiHost")
this.apDomain = tmpApDomain ?: tmpApiHost ?: tmpAcct.host ?: error("missing apDomain")
this.acct = tmpAcct.followHost(apDomain)
}