[yaml parser] Fix FQN=//node_name when ns is / (#299)
* Fix FQN=//node_name when ns is / * Check end of string for ns sep * Add regression test
This commit is contained in:
parent
0a6d9186e8
commit
f1293b7d3b
3 changed files with 40 additions and 1 deletions
|
@ -187,7 +187,14 @@ static rcl_ret_t add_name_to_ns(
|
|||
ns_len = strlen(cur_ns);
|
||||
name_len = strlen(name);
|
||||
sep_len = strlen(sep_str);
|
||||
tot_len = ns_len + name_len + sep_len + 1U;
|
||||
// Check the last sep_len characters of the current NS against the separator string.
|
||||
if (strcmp(cur_ns + ns_len - sep_len, sep_str) == 0) {
|
||||
// Current NS already ends with the separator: don't put another separator in.
|
||||
sep_len = 0;
|
||||
sep_str = "";
|
||||
}
|
||||
|
||||
tot_len = ns_len + sep_len + name_len + 1U;
|
||||
|
||||
if (tot_len > MAX_STRING_SIZE) {
|
||||
RCL_SET_ERROR_MSG("New namespace string is exceeding max string size",
|
||||
|
|
7
rcl_yaml_param_parser/test/root_ns.yaml
Normal file
7
rcl_yaml_param_parser/test/root_ns.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# config/test_yaml
|
||||
---
|
||||
|
||||
/:
|
||||
my_node:
|
||||
ros__parameters:
|
||||
param_name: 'value'
|
|
@ -62,6 +62,31 @@ TEST(test_file_parser, multi_ns_correct_syntax) {
|
|||
allocator.deallocate(path, allocator.state);
|
||||
}
|
||||
|
||||
TEST(test_file_parser, root_ns) {
|
||||
rcutils_reset_error();
|
||||
EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024));
|
||||
rcutils_allocator_t allocator = rcutils_get_default_allocator();
|
||||
char * test_path = rcutils_join_path(cur_dir, "test", allocator);
|
||||
char * path = rcutils_join_path(test_path, "root_ns.yaml", allocator);
|
||||
fprintf(stderr, "cur_path: %s\n", path);
|
||||
EXPECT_TRUE(rcutils_exists(path));
|
||||
rcl_params_t * params_hdl = rcl_yaml_node_struct_init(allocator);
|
||||
EXPECT_FALSE(NULL == params_hdl);
|
||||
bool res = rcl_parse_yaml_file(path, params_hdl);
|
||||
fprintf(stderr, "%s\n", rcutils_get_error_string_safe());
|
||||
EXPECT_TRUE(res);
|
||||
rcl_yaml_node_struct_print(params_hdl);
|
||||
|
||||
// Check that there is only one forward slash in the node's FQN.
|
||||
// (Regression test for https://github.com/ros2/rcl/pull/299).
|
||||
ASSERT_EQ(1u, params_hdl->num_nodes);
|
||||
ASSERT_STREQ("/my_node", params_hdl->node_names[0]);
|
||||
|
||||
rcl_yaml_node_struct_fini(params_hdl);
|
||||
allocator.deallocate(test_path, allocator.state);
|
||||
allocator.deallocate(path, allocator.state);
|
||||
}
|
||||
|
||||
TEST(test_file_parser, seq_map1) {
|
||||
rcutils_reset_error();
|
||||
EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue