diff --git a/gura/GuraParser.py b/gura/GuraParser.py index 68aa79b..e71c5f6 100644 --- a/gura/GuraParser.py +++ b/gura/GuraParser.py @@ -463,7 +463,6 @@ def pair(self) -> Optional[MatchResult]: key = self.match('key') self.maybe_match('ws') - self.maybe_match('new_line') # Check indentation last_indentation_block = self.__get_last_indentation_level() @@ -503,6 +502,11 @@ def pair(self) -> Optional[MatchResult]: else: result = result.value + # Prevents issues with indentation inside a list that break objects + if isinstance(result, list): + self.__remove_last_indentation_level() + self.indentation_levels.append(current_indentation_level) + self.maybe_match('new_line') return MatchResult(MatchResultType.PAIR, (key, result, current_indentation_level)) diff --git a/tests/arrays/test.py b/tests/arrays/test.py index bdaca47..25bdc98 100644 --- a/tests/arrays/test.py +++ b/tests/arrays/test.py @@ -61,6 +61,19 @@ def setUp(self): } } + self.expected_trailing_comma = { + "foo": [ + { + "bar": { + "baz": [ + {"far": "faz"} + ] + } + } + ], + "barbaz": "boo" + } + def __get_file_parsed_data(self, file_name) -> Dict: """ Gets the content of a specific file parsed @@ -82,6 +95,12 @@ def test_with_comments(self): parsed_data = self.__get_file_parsed_data('with_comments.ura') self.assertDictEqual(parsed_data, self.expected) + def test_bug_trailing_comma(self): + """Tests a bug that breaks arrays with a mandatory trailing comma. In this case the trailing comma is missing + and it should parse correctly""" + parsed_data = self.__get_file_parsed_data('bug_trailing_comma.ura') + self.assertDictEqual(parsed_data, self.expected_trailing_comma) + def test_array_in_object(self): """Tests issue https://github.com/gura-conf/gura/issues/1""" parsed_data = self.__get_file_parsed_data('array_in_object.ura') diff --git a/tests/arrays/tests-files/bug_trailing_comma.ura b/tests/arrays/tests-files/bug_trailing_comma.ura new file mode 100644 index 0000000..46424e1 --- /dev/null +++ b/tests/arrays/tests-files/bug_trailing_comma.ura @@ -0,0 +1,7 @@ +foo: [ + bar: + baz: [ + far: "faz" + ], +] +barbaz: "boo" \ No newline at end of file