Skip to content

Commit

Permalink
ref: Switch the internal representation of project IDs from ints over…
Browse files Browse the repository at this point in the history
… to char*s
  • Loading branch information
relaxolotl committed Mar 29, 2022
1 parent 9eecb1b commit 5194c0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/sentry_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ sentry__dsn_new(const char *raw_dsn)
sentry_url_t url;
memset(&url, 0, sizeof(sentry_url_t));
size_t path_len;
long long project_id;
char *tmp;
char *end;

Expand Down Expand Up @@ -259,12 +260,16 @@ sentry__dsn_new(const char *raw_dsn)
if (!tmp) {
goto exit;
}

dsn->project_id = (uint64_t)strtoll(tmp + 1, &end, 10);
// Validate that the project ID is still a valid number until sentry fully
// commits to pure string project IDs
project_id = strtoll(tmp + 1, &end, 10);
if (end != tmp + strlen(tmp)) {
goto exit;
}

dsn->project_id = sentry__string_clone(tmp + 1);
*tmp = 0;

dsn->path = url.path;
url.path = NULL;

Expand Down Expand Up @@ -329,7 +334,7 @@ init_string_builder_for_url(sentry_stringbuilder_t *sb, const sentry_dsn_t *dsn)
sentry__stringbuilder_append_int64(sb, (int64_t)dsn->port);
sentry__stringbuilder_append(sb, dsn->path);
sentry__stringbuilder_append(sb, "/api/");
sentry__stringbuilder_append_int64(sb, (int64_t)dsn->project_id);
sentry__stringbuilder_append(sb, dsn->project_id);
}

char *
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct sentry_dsn_s {
char *path;
char *secret_key;
char *public_key;
uint64_t project_id;
char *project_id;
int port;
long refcount;
bool is_valid;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SENTRY_TEST(dsn_parsing_complete)
TEST_CHECK_STRING_EQUAL(dsn->public_key, "username");
TEST_CHECK_STRING_EQUAL(dsn->secret_key, "password");
TEST_CHECK_STRING_EQUAL(dsn->path, "/foo/bar");
TEST_CHECK_INT_EQUAL((int)dsn->project_id, 42);
TEST_CHECK_STRING_EQUAL(dsn->project_id, "42");
sentry__dsn_decref(dsn);

dsn = sentry__dsn_new("https://username@example.com/42");
Expand All @@ -97,7 +97,7 @@ SENTRY_TEST(dsn_parsing_complete)
TEST_CHECK_STRING_EQUAL(dsn->public_key, "username");
TEST_CHECK(!dsn->secret_key);
TEST_CHECK_STRING_EQUAL(dsn->path, "");
TEST_CHECK_INT_EQUAL((int)dsn->project_id, 42);
TEST_CHECK_STRING_EQUAL(dsn->project_id, "42");
sentry__dsn_decref(dsn);
}

Expand Down

0 comments on commit 5194c0e

Please sign in to comment.