From bf9ec9f8aecd987bee63e6c0af4164c7be14b42f Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Tue, 24 Sep 2024 07:21:37 -0700 Subject: [PATCH] Add REST test for requesting entity with / in name --- test/addons/project.json | 3 ++- test/addons/src/Rest.c | 25 +++++++++++++++++++++++++ test/addons/src/main.c | 7 ++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/test/addons/project.json b/test/addons/project.json index 3fce60ab0..4af6cc6d9 100644 --- a/test/addons/project.json +++ b/test/addons/project.json @@ -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", diff --git a/test/addons/src/Rest.c b/test/addons/src/Rest.c index 4dd3f8b1e..b527316b6 100644 --- a/test/addons/src/Rest.c +++ b/test/addons/src/Rest.c @@ -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); +} diff --git a/test/addons/src/main.c b/test/addons/src/main.c index 608cfaaba..899e3f03d 100644 --- a/test/addons/src/main.c +++ b/test/addons/src/main.c @@ -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); @@ -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 } }; @@ -2655,7 +2660,7 @@ static bake_test_suite suites[] = { "Rest", NULL, NULL, - 17, + 18, Rest_testcases }, {