From 75d98df4bf3cf894750fec142450c5c65d7b1e36 Mon Sep 17 00:00:00 2001 From: Marko Durkovic Date: Mon, 4 Oct 2021 16:46:22 +0200 Subject: [PATCH] Do not match msg separator as constant value --- src/rosbags/typesys/msg.py | 2 +- tests/test_parse.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/rosbags/typesys/msg.py b/src/rosbags/typesys/msg.py index 8b326905..9eda4e46 100644 --- a/src/rosbags/typesys/msg.py +++ b/src/rosbags/typesys/msg.py @@ -44,7 +44,7 @@ comment = r'#[^\n]*' const_dcl - = 'string' identifier '=' r'[^\n]+' + = 'string' identifier r'=(?!={79}\n)' r'[^\n]+' / type_spec identifier '=' integer_literal field_dcl diff --git a/tests/test_parse.py b/tests/test_parse.py index 7f51ba85..00783d91 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -45,6 +45,15 @@ uint64[3] Header uint32 static = 42 """ +CSTRING_CONFUSION_MSG = """ +std_msgs/Header header +string s + +================================================================================ +MSG: std_msgs/Header +time time +""" + RELSIBLING_MSG = """ Header header Other other @@ -144,6 +153,18 @@ def test_parse_multi_msg(): assert consts == [('static', 'uint32', 42)] +def test_parse_cstring_confusion(): + """Test if msg separator is confused with const string.""" + ret = get_types_from_msg(CSTRING_CONFUSION_MSG, 'test_msgs/msg/Foo') + assert len(ret) == 2 + assert 'test_msgs/msg/Foo' in ret + assert 'std_msgs/msg/Header' in ret + consts, fields = ret['test_msgs/msg/Foo'] + assert consts == [] + assert fields[0][1][1] == 'std_msgs/msg/Header' + assert fields[1][1][1] == 'string' + + def test_parse_relative_siblings_msg(): """Test relative siblings with msg parser.""" ret = get_types_from_msg(RELSIBLING_MSG, 'test_msgs/msg/Foo')