Skip to content

Commit

Permalink
Merge pull request #148 from Nordix/faulty-slug-in-insert-route
Browse files Browse the repository at this point in the history
Handle incomplete slug pattern when inserting a route
  • Loading branch information
c9s authored Nov 5, 2021
2 parents 90450de + 2f3e0b0 commit 76e2770
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ R3Route * r3_node_append_route(R3Node *tree, const char * path, int path_len, in
*/
R3Route * r3_tree_insert_routel_ex(R3Node *tree, int method, const char *path, int path_len, void *data, char **errstr) {
R3Node * ret = r3_tree_insert_pathl_ex(tree, path, path_len, method, 1, data, errstr);
if (ret == NULL) {
return NULL;
}
R3Route *router = ret->routes.entries + (ret->routes.size - 1);
get_slugs(router, path, path_len);

Expand Down
17 changes: 17 additions & 0 deletions tests/check_routes2.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,28 @@ START_TEST (common_pattern)
}
END_TEST

START_TEST (incomplete_pattern)
{
R3Node * n = r3_tree_create(10);
R3Route * r;

char * uri0 = "{slug";
r = r3_tree_insert_routel(n, 0, uri0, strlen(uri0), &uri0);
ck_assert(r == NULL);
char * uri1 = "/foo/{slug";
r = r3_tree_insert_routel(n, 0, uri1, strlen(uri1), &uri1);
ck_assert(r == NULL);

r3_tree_free(n);
}
END_TEST

Suite* r3_suite (void) {
Suite *suite = suite_create("r3 routes2 tests");
TCase *tcase = tcase_create("testcase");
tcase_add_test(tcase, greedy_pattern);
tcase_add_test(tcase, common_pattern);
tcase_add_test(tcase, incomplete_pattern);
suite_add_tcase(suite, tcase);
return suite;
}
Expand Down

0 comments on commit 76e2770

Please sign in to comment.