Skip to content

Commit

Permalink
Add REST test for requesting entity with / in name
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 24, 2024
1 parent 343ac35 commit bf9ec9f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/addons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
"script_error",
"import_rest_after_mini",
"get_pipeline_stats_after_delete_system",
"request_world_summary_before_monitor_sys_run"
"request_world_summary_before_monitor_sys_run",
"escape_backslash"
]
}, {
"id": "Metrics",
Expand Down
25 changes: 25 additions & 0 deletions test/addons/src/Rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,28 @@ void Rest_request_world_summary_before_monitor_sys_run(void) {

ecs_fini(world);
}

void Rest_escape_backslash(void) {
ecs_world_t *world = ecs_init();

ECS_IMPORT(world, FlecsStats);

ecs_http_server_t *srv = ecs_rest_server_init(world, NULL);
test_assert(srv != NULL);

ecs_entity(world, { .name = "foo/bar" });

ecs_http_reply_t reply = ECS_HTTP_REPLY_INIT;
test_int(0, ecs_http_server_request(srv, "GET",
"/entity/foo%5C%2Fbar", &reply));
test_int(reply.code, 200);

char *reply_str = ecs_strbuf_get(&reply.body);
test_assert(reply_str != NULL);
test_str(reply_str, "{\"name\":\"foo/bar\"}");
ecs_os_free(reply_str);

ecs_rest_server_fini(srv);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/addons/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ void Rest_script_error(void);
void Rest_import_rest_after_mini(void);
void Rest_get_pipeline_stats_after_delete_system(void);
void Rest_request_world_summary_before_monitor_sys_run(void);
void Rest_escape_backslash(void);

// Testsuite 'Metrics'
void Metrics_member_gauge_1_entity(void);
Expand Down Expand Up @@ -2203,6 +2204,10 @@ bake_test_case Rest_testcases[] = {
{
"request_world_summary_before_monitor_sys_run",
Rest_request_world_summary_before_monitor_sys_run
},
{
"escape_backslash",
Rest_escape_backslash
}
};

Expand Down Expand Up @@ -2655,7 +2660,7 @@ static bake_test_suite suites[] = {
"Rest",
NULL,
NULL,
17,
18,
Rest_testcases
},
{
Expand Down

0 comments on commit bf9ec9f

Please sign in to comment.