rosidl
rosidl copied to clipboard
Escape default arrays and sequences the same other default values
Fixes #610
As a regression test, I've added a new field to one of the test messages: https://github.com/ros2/test_interface_files/pull/16
Rpr fails because https://github.com/ament/ament_cmake/pull/352 has not been released.
This is interesting. I can't predict if it will pass the test_communication
tests. I recommend adding another test to test_interface_files with "ハローワールド"
to see what it does when given a string with characters outside the latin-1 character set.
https://github.com/ros2/test_interface_files/blob/ea4d4f33eca97f37b4294e6ab012fa0f216de609/msg/WStrings.msg#L2-L4
IIUC Hellö wörld!"
in that .msg
file is encoded as the UTF-8 bytes b'Hell\xc3\xb6 w\xc3\xb6rld!'
. When read as latin-1
the string in Python would be very different from the original.
>>> b'Hell\xc3\xb6 w\xc3\xb6rld!'.decode('latin-1')
'Hellö wörld!'
When re-encoded as latin-1
that should output the original bytes, but there's some more weirdness when the generators read the idl files.
https://github.com/ros2/rosidl/blob/36ed120f43daeaab31fd9ba2bf8dfb58db05091d/rosidl_parser/rosidl_parser/parser.py#L660
IIUC Hellö wörld!" in that .msg file is encoded as the UTF-8 bytes b'Hell\xc3\xb6 w\xc3\xb6rld!'. When read as latin-1 the string in Python would be very different from the original.
In fact there were test failures related to this that I missed locally: https://ci.ros2.org/job/ci_linux/15332/testReport/junit/rosidl_generator_py.test/test_interfaces/test_wstrings/
I think the issue was due to a difference in how we handled default values of arrays and sequences compared with other default values. See 8253770, which applies similar logic to array/sequence defaults as we do with other defaults, e.g.
https://github.com/ros2/rosidl/blob/36ed120f43daeaab31fd9ba2bf8dfb58db05091d/rosidl_adapter/rosidl_adapter/msg/init.py#L78-L79