Skip to content

Commit

Permalink
Fix srv definition parsing failing due to carriage return (#303)
Browse files Browse the repository at this point in the history
### Changelog
Fix srv definition parsing failing due to carriage return

### Docs
None

### Description
Fixes srv (or action) definition parsing failing when the definition
seperator `---` is terminated with `\r\n` instead of just `\n`. More
details in #301.

Fixes: #301
  • Loading branch information
achim-k authored Jun 11, 2024
1 parent 15df098 commit 4fcf613
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ros2_foxglove_bridge/include/foxglove_bridge/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ inline std::vector<std::string> splitMessageDefinitions(std::istream& stream) {
std::string definition = "";

while (std::getline(stream, line)) {
line = trimString(line);
if (line == "---") {
definitions.push_back(trimString(definition));
definition = "";
Expand Down
11 changes: 11 additions & 0 deletions ros2_foxglove_bridge/tests/utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ TEST(SplitDefinitionsTest, ActionDefinitionNoGoal) {
EXPECT_EQ(definitions[2], "bool feedback");
}

TEST(SplitDefinitionsTest, HandleCarriageReturn) {
const std::string messageDef =
"---\r\n"
"string device_name\n";
std::istringstream stream(messageDef);
const auto definitions = foxglove_bridge::splitMessageDefinitions(stream);
ASSERT_EQ(definitions.size(), 2u);
EXPECT_EQ(definitions[0], "");
EXPECT_EQ(definitions[1], "string device_name");
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit 4fcf613

Please sign in to comment.