Skip to content

Commit

Permalink
remove almost all checking except for emptiness
Browse files Browse the repository at this point in the history
  • Loading branch information
relaxolotl committed Mar 30, 2022
1 parent 5194c0e commit bfb8334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
18 changes: 5 additions & 13 deletions src/sentry_utils.c
Expand Up @@ -218,9 +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;
char *project_id;

sentry_dsn_t *dsn = SENTRY_MAKE(sentry_dsn_t);
if (!dsn) {
Expand Down Expand Up @@ -256,19 +254,13 @@ sentry__dsn_new(const char *raw_dsn)
path_len--;
}

tmp = strrchr(url.path, '/');
if (!tmp) {
goto exit;
}
// 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)) {
project_id = strrchr(url.path, '/');
if (!project_id || strlen(project_id + 1) == 0) {
goto exit;
}

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

dsn->path = url.path;
url.path = NULL;
Expand Down
30 changes: 16 additions & 14 deletions tests/unit/test_utils.c
Expand Up @@ -71,7 +71,7 @@ SENTRY_TEST(url_parsing_invalid)
SENTRY_TEST(dsn_parsing_complete)
{
sentry_dsn_t *dsn = sentry__dsn_new(
"http://username:password@example.com/foo/bar/42?x=y#z");
"http://username:password@example.com/foo/bar/42%21?x=y#z");
TEST_CHECK(!!dsn);
if (!dsn) {
return;
Expand All @@ -83,10 +83,10 @@ 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_STRING_EQUAL(dsn->project_id, "42");
TEST_CHECK_STRING_EQUAL(dsn->project_id, "42%21");
sentry__dsn_decref(dsn);

dsn = sentry__dsn_new("https://username@example.com/42");
dsn = sentry__dsn_new("https://username@example.com/42%21");
TEST_CHECK(!!dsn);
if (!dsn) {
return;
Expand All @@ -97,22 +97,24 @@ 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_STRING_EQUAL(dsn->project_id, "42");
TEST_CHECK_STRING_EQUAL(dsn->project_id, "42%21");
sentry__dsn_decref(dsn);
}

SENTRY_TEST(dsn_parsing_invalid)
{
sentry_dsn_t *dsn
= sentry__dsn_new("http://username:password@example.com/foo/bar?x=y#z");
dsn = sentry__dsn_new("https://username@example.com/pathone/pathtwo/42%21");
TEST_CHECK(!!dsn);
if (dsn) {
TEST_CHECK(!dsn->is_valid);
sentry__dsn_decref(dsn);
if (!dsn) {
return;
}
TEST_CHECK(dsn->is_valid);
TEST_CHECK_STRING_EQUAL(dsn->path, "/pathone/pathtwo");
TEST_CHECK_STRING_EQUAL(dsn->project_id, "42%21");
sentry__dsn_decref(dsn);
}

dsn = sentry__dsn_new("=https://foo@bar.ingest.sentry.io/"
"1234567");
SENTRY_TEST(dsn_parsing_invalid)
{
sentry_dsn_t *dsn = sentry__dsn_new("=https://foo@bar.ingest.sentry.io/"
"1234567");
TEST_CHECK(!!dsn);
if (dsn) {
TEST_CHECK(!dsn->is_valid);
Expand Down

0 comments on commit bfb8334

Please sign in to comment.