Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion packages/cli/src/lib/envelope/event-send-dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { resolveIngestDsn } from "./transport.js";

const log = logger.withTag("event.send");
const DSN_PREFIX_RE = /^https?:\/\//i;
const TRAILING_SLASHES_RE = /\/+$/;

/** Usage example shown on missing-DSN errors. */
function eventSendDsnHint(): string {
Expand Down Expand Up @@ -79,7 +80,9 @@ export async function resolveEventSendDsn(
target: EventSendTarget | undefined,
): Promise<string> {
if (target?.kind === "dsn") {
return target.dsn.trim();
// makeDsn rejects a trailing slash (empty project ID segment), but users
// often paste DSNs like `https://key@host/123/`. Normalize it away.
return target.dsn.trim().replace(TRAILING_SLASHES_RE, "");
}
if (target?.kind === "project") {
return await dsnFromProjectTarget(target.target, cwd);
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/test/lib/envelope/event-send-dsn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ describe("resolveEventSendDsn", () => {
expect(detectSpy).not.toHaveBeenCalled();
});

test("positional DSN with trailing slashes is normalized", async () => {
const dsn = await resolveEventSendDsn("/tmp", {
kind: "dsn",
dsn: ` ${SAAS_DSN}// `,
});
expect(dsn).toBe(SAAS_DSN);
});

test("project target wins over SENTRY_DSN and project scan", async () => {
process.env["SENTRY_DSN"] = OTHER_DSN;
authSpy.mockReturnValue(OAUTH_SESSION);
Expand Down
Loading