Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Trim DSN string before parsing to avoid `URISyntaxException` caused by trailing whitespace ([#5113](https://github.com/getsentry/sentry-java/pull/5113))

## 8.33.0

### Features
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Dsn.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ URI getSentryUri() {

Dsn(@Nullable String dsn) throws IllegalArgumentException {
try {
Objects.requireNonNull(dsn, "The DSN is required.");
final URI uri = new URI(dsn).normalize();
final String dsnString = Objects.requireNonNull(dsn, "The DSN is required.").trim();
Comment thread
cursor[bot] marked this conversation as resolved.
final URI uri = new URI(dsnString).normalize();
Comment thread
cursor[bot] marked this conversation as resolved.
final String scheme = uri.getScheme();
if (!("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))) {
throw new IllegalArgumentException("Invalid DSN scheme: " + scheme);
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/test/java/io/sentry/DsnTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class DsnTest {
assertEquals("http://host/api/id", dsn.sentryUri.toURL().toString())
}

@Test
fun `dsn parsed with leading and trailing whitespace`() {
val dsn = Dsn(" https://key@host/id ")
assertEquals("https://host/api/id", dsn.sentryUri.toURL().toString())
}

@Test
fun `non http protocols are not accepted`() {
assertFailsWith<IllegalArgumentException> { Dsn("ftp://publicKey:secretKey@host/path/id") }
Expand Down
Loading