RobotWebTools / rosbridge_suite

Server Implementations of the rosbridge v2 Protocol
https://robotwebtools.github.io
BSD 3-Clause "New" or "Revised" License
866 stars 506 forks source link

NaNs not handled correctly when in an array #916

Open JayHerpin opened 3 months ago

JayHerpin commented 3 months ago

I've seen that there is explicit handling for NaN's in the json messages, but this seems not to be extended to NaNs within arrays.

Steps To Reproduce

Run command:

ros2 topic pub /fix sensor_msgs/msg/NavSatFix "{latitude : .nan, longitude : .nan, altitude : .nan, status : {status : -1, service : 1}, position_covariance : [.nan, .nan, .nan, .nan, .nan, .nan, .nan, .nan, .nan]}"

to publish problematic data

Subscribe to topic /fix from nodejs or similar

Expected Behavior All NaN values in the encoded json message should be encoded as :Null

Actual Behavior

As you can see, while the non-array members are encoded correctly, the values within the array are not

image

RamiCMT commented 3 months ago

This has been causing problems for roslibjs as well.

If I have a serial GPS node publishing data without proper reception, missing values encoded as NaN cause roslibjs' subscriber's JSON.parse() to throw an error.

Screenshot from 2024-04-01 14-09-20