Skip to content

Commit 0a7e3bd

Browse files
committed
Fix whitespace-only DSN handling
1 parent e20e757 commit 0a7e3bd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,12 @@ Dsn retrieveParsedDsn() throws IllegalArgumentException {
749749
* @param dsn the DSN
750750
*/
751751
public void setDsn(final @Nullable String dsn) {
752-
this.dsn = dsn != null ? dsn.trim() : null;
752+
if (dsn == null) {
753+
this.dsn = null;
754+
} else {
755+
final String trimmedDsn = dsn.trim();
756+
this.dsn = trimmedDsn.isEmpty() && !dsn.isEmpty() ? dsn : trimmedDsn;
757+
}
753758
this.parsedDsn.resetValue();
754759

755760
dsnHash = StringUtils.calculateStringHash(this.dsn, logger);

sentry/src/test/java/io/sentry/SentryTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ class SentryTest {
340340
)
341341
}
342342

343+
@Test
344+
fun `initializes Sentry with whitespace-only dsn, throwing IllegalArgumentException`() {
345+
assertThrows(java.lang.IllegalArgumentException::class.java) { initForTest { it.dsn = " " } }
346+
}
347+
343348
@Test
344349
fun `captureUserFeedback gets forwarded to client`() {
345350
initForTest { it.dsn = dsn }

0 commit comments

Comments
 (0)