Skip to content

Commit

Permalink
fix NPE on UrlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Sep 29, 2024
1 parent 67da0bb commit 6959ac1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion common/src/main/java/com/pedro/common/UrlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class UrlParser private constructor(
@Throws(URISyntaxException::class)
fun parse(endpoint: String, requiredProtocol: Array<String>): UrlParser {
val uri = URI(endpoint)
if (!requiredProtocol.contains(uri.scheme.trim())) {
if (uri.scheme != null && !requiredProtocol.contains(uri.scheme.trim())) {
throw URISyntaxException(endpoint, "Invalid protocol: ${uri.scheme}")
}
if (uri.userInfo != null && !uri.userInfo.contains(":")) {
throw URISyntaxException(endpoint, "Invalid auth. Auth must contain ':'")
}
if (uri.host == null) throw URISyntaxException(endpoint, "Invalid host: ${uri.host}")
if (uri.path == null) throw URISyntaxException(endpoint, "Invalid path: ${uri.host}")
return UrlParser(uri, endpoint)
}
}
Expand Down

0 comments on commit 6959ac1

Please sign in to comment.