Skip to content

Commit ff0acf5

Browse files
runningcodeclaude
andcommitted
Add URL encoding and null safety to DistributionHttpClient
- Add URLEncoder for proper encoding of query parameters and path segments - Change isEmpty() to isNullOrEmpty() for null safety on configuration values - Prevents malformed URLs with special characters and NullPointerExceptions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b238c29 commit ff0acf5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

sentry-android-distribution/src/main/java/io/sentry/android/distribution/DistributionHttpClient.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.IOException
77
import java.io.InputStreamReader
88
import java.net.HttpURLConnection
99
import java.net.URL
10+
import java.net.URLEncoder
1011
import javax.net.ssl.HttpsURLConnection
1112

1213
/** HTTP client for making requests to Sentry's distribution API. */
@@ -41,20 +42,22 @@ internal class DistributionHttpClient(private val options: SentryOptions) {
4142
val authToken = distributionOptions.orgAuthToken
4243
val baseUrl = distributionOptions.sentryBaseUrl
4344

44-
if (orgSlug.isEmpty() || projectSlug.isEmpty() || authToken.isEmpty()) {
45+
if (orgSlug.isNullOrEmpty() || projectSlug.isNullOrEmpty() || authToken.isNullOrEmpty()) {
4546
throw IllegalStateException(
4647
"Missing required distribution configuration: orgSlug, projectSlug, or orgAuthToken"
4748
)
4849
}
4950

5051
val urlString = buildString {
5152
append(baseUrl.trimEnd('/'))
52-
append("/api/0/projects/$orgSlug/$projectSlug/preprodartifacts/check-for-updates/")
53-
append("?main_binary_identifier=${params.mainBinaryIdentifier}")
54-
append("&app_id=${params.appId}")
55-
append("&platform=${params.platform}")
56-
append("&build_number=${params.versionCode}")
57-
append("&build_version=${params.versionName}")
53+
append(
54+
"/api/0/projects/${URLEncoder.encode(orgSlug, "UTF-8")}/${URLEncoder.encode(projectSlug, "UTF-8")}/preprodartifacts/check-for-updates/"
55+
)
56+
append("?main_binary_identifier=${URLEncoder.encode(params.mainBinaryIdentifier, "UTF-8")}")
57+
append("&app_id=${URLEncoder.encode(params.appId, "UTF-8")}")
58+
append("&platform=${URLEncoder.encode(params.platform, "UTF-8")}")
59+
append("&build_number=${URLEncoder.encode(params.versionCode.toString(), "UTF-8")}")
60+
append("&build_version=${URLEncoder.encode(params.versionName, "UTF-8")}")
5861
}
5962
val url = URL(urlString)
6063

0 commit comments

Comments
 (0)