Allow empty strings if they are quoted. (#450)
Signed-off-by: Ralf Anton Beier <ralf_beier@me.com>
This commit is contained in:
parent
9566f39d60
commit
5f0d331712
3 changed files with 32 additions and 1 deletions
|
@ -849,7 +849,10 @@ static rcl_ret_t parse_value(
|
||||||
"Scalar value at line %d is bigger than %d bytes", line_num, MAX_STRING_SIZE);
|
"Scalar value at line %d is bigger than %d bytes", line_num, MAX_STRING_SIZE);
|
||||||
return RCL_RET_ERROR;
|
return RCL_RET_ERROR;
|
||||||
} else {
|
} else {
|
||||||
if (0U == val_size) {
|
if (style != YAML_SINGLE_QUOTED_SCALAR_STYLE &&
|
||||||
|
style != YAML_DOUBLE_QUOTED_SCALAR_STYLE &&
|
||||||
|
0U == val_size)
|
||||||
|
{
|
||||||
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("No value at line %d", line_num);
|
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("No value at line %d", line_num);
|
||||||
return RCL_RET_ERROR;
|
return RCL_RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
9
rcl_yaml_param_parser/test/empty_string.yaml
Normal file
9
rcl_yaml_param_parser/test/empty_string.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# config/test_yaml
|
||||||
|
---
|
||||||
|
|
||||||
|
lidar_ns:
|
||||||
|
lidar_1:
|
||||||
|
ros__parameters:
|
||||||
|
id: 10
|
||||||
|
name: ""
|
||||||
|
another: ''
|
|
@ -172,6 +172,25 @@ TEST(test_file_parser, max_string_sz) {
|
||||||
allocator.deallocate(path, allocator.state);
|
allocator.deallocate(path, allocator.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(test_file_parser, empty_string) {
|
||||||
|
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, "empty_string.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().str);
|
||||||
|
EXPECT_TRUE(res);
|
||||||
|
rcl_yaml_node_struct_print(params_hdl);
|
||||||
|
rcl_yaml_node_struct_fini(params_hdl);
|
||||||
|
allocator.deallocate(test_path, allocator.state);
|
||||||
|
allocator.deallocate(path, allocator.state);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(test_file_parser, no_value1) {
|
TEST(test_file_parser, no_value1) {
|
||||||
rcutils_reset_error();
|
rcutils_reset_error();
|
||||||
EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024));
|
EXPECT_TRUE(rcutils_get_cwd(cur_dir, 1024));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue