Skip to content

Commit

Permalink
Handle zero-width string parameters. (ros2#72)
Browse files Browse the repository at this point in the history
* Handle zero-width string parameters.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Restore yaml.safe_load usage.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored Sep 23, 2019
1 parent d25e2b3 commit b04713d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions launch_ros/launch_ros/utilities/evaluate_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def check_sequence_type_is_allowed(sequence):
# Value is a list of substitutions, so perform them to make a string
evaluated_value = perform_substitutions(context, list(value))
yaml_evaluated_value = yaml.safe_load(evaluated_value)
if yaml_evaluated_value is None:
yaml_evaluated_value = ''
if type(yaml_evaluated_value) in (bool, int, float, str, bytes):
evaluated_value = yaml_evaluated_value
elif isinstance(yaml_evaluated_value, Sequence):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ros__parameters:
some_int: 42
a_string: "Hello world"
no_string: ""
some_list:
sub_list:
some_integers: [1, 2, 3, 4]
Expand Down
4 changes: 3 additions & 1 deletion test_launch_ros/test/test_launch_ros/actions/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def test_launch_node_with_parameter_dict(self):
'param_group2': {
(EnvironmentVariable('PARAM2'), '_values'): ['param2_value'],
}
}
},
'param3': ''
}],
)
self._assert_launch_no_errors([node_action])
Expand All @@ -166,6 +167,7 @@ def test_launch_node_with_parameter_dict(self):
'ros__parameters': {
'param1': 'param1_value',
'param2': 'param2_value',
'param3': '',
'param_group1.list_params': (1.2, 3.4),
'param_group1.param_group2.param2_values': ('param2_value',),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<param name="param9" value="\'2\', \'5\', \'8\'" value-sep=", "/>
<param name="param10" value="''asd'', ''bsd'', ''csd''" value-sep=", "/>
<param name="param11" value="'\asd', '\bsd', '\csd'" value-sep=", "/>
<param name="param12" value=""/>
</param>
<param from="{}"/>
<env name="var" value="1"/>
Expand Down Expand Up @@ -96,6 +97,8 @@
value: ["'asd'", "'bsd'", "'csd'"]
- name: param11
value: ['\asd', '\bsd', '\csd']
- name: param12
value: ''
- from: {}
env:
- name: var
Expand Down Expand Up @@ -141,3 +144,4 @@ def test_node_frontend(file):
assert param_dict['param_group1.param9'] == ("'2'", "'5'", "'8'")
assert param_dict['param_group1.param10'] == ("'asd'", "'bsd'", "'csd'")
assert param_dict['param_group1.param11'] == ('asd', 'bsd', 'csd')
assert param_dict['param_group1.param12'] == ''

0 comments on commit b04713d

Please sign in to comment.