Avoid code duplication
This commit is contained in:
parent
c96ad7addc
commit
6b2c48972c
1 changed files with 11 additions and 12 deletions
|
|
@ -32,25 +32,24 @@ class CallIntentDataParser @Inject constructor() {
|
||||||
scheme == "element" && parsedUrl.host == "call" -> {
|
scheme == "element" && parsedUrl.host == "call" -> {
|
||||||
// We use this custom scheme to load arbitrary URLs for other instances of Element Call,
|
// We use this custom scheme to load arbitrary URLs for other instances of Element Call,
|
||||||
// so we can only verify it's an HTTP/HTTPs URL with a non-empty host
|
// so we can only verify it's an HTTP/HTTPs URL with a non-empty host
|
||||||
parsedUrl.getQueryParameter("url")
|
parsedUrl.getUrlParameter()
|
||||||
?.let { URLDecoder.decode(it, "utf-8") }
|
|
||||||
?.takeIf {
|
|
||||||
val internalUri = Uri.parse(it)
|
|
||||||
internalUri.scheme in validHttpSchemes && !internalUri.host.isNullOrBlank()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
scheme == "io.element.call" && parsedUrl.host == null -> {
|
scheme == "io.element.call" && parsedUrl.host == null -> {
|
||||||
// We use this custom scheme to load arbitrary URLs for other instances of Element Call,
|
// We use this custom scheme to load arbitrary URLs for other instances of Element Call,
|
||||||
// so we can only verify it's an HTTP/HTTPs URL with a non-empty host
|
// so we can only verify it's an HTTP/HTTPs URL with a non-empty host
|
||||||
parsedUrl.getQueryParameter("url")
|
parsedUrl.getUrlParameter()
|
||||||
?.let { URLDecoder.decode(it, "utf-8") }
|
|
||||||
?.takeIf {
|
|
||||||
val internalUri = Uri.parse(it)
|
|
||||||
internalUri.scheme in validHttpSchemes && !internalUri.host.isNullOrBlank()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// This should never be possible, but we still need to take into account the possibility
|
// This should never be possible, but we still need to take into account the possibility
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Uri.getUrlParameter(): String? {
|
||||||
|
return getQueryParameter("url")
|
||||||
|
?.let { URLDecoder.decode(it, "utf-8") }
|
||||||
|
?.takeIf {
|
||||||
|
val internalUri = Uri.parse(it)
|
||||||
|
internalUri.scheme in validHttpSchemes && !internalUri.host.isNullOrBlank()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue