From 87812d3e33d8a9208913c81acc4473d984cec7b5 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 12:21:17 +0100 Subject: [PATCH] Handle dangling newlines --- mark2confluence/main.py | 4 +++- tests/test_main.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 9f6507c..f5e6769 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -228,7 +228,9 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]: if not parents_string: return [] default_parents = list() - for parent_string in parents_string.split("\n"): + parents_string_array = parents_string.split("\n") + parents_string_array = list(filter(lambda x: x, parents_string_array)) + for parent_string in parents_string_array: directory, space, parents = _parse_parent_string(parent_string) default_parents.append(ParentCfg(directory, space, parents)) default_parents.sort(key=lambda cfg: len(cfg.directory), reverse=True) diff --git a/tests/test_main.py b/tests/test_main.py index d656e0a..11f9042 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -94,6 +94,7 @@ def test__parse_parents_string(string, expected_dir, expected_space, expected_pa "string,expected_parents_count", [ ("tools/=foo", 1), + ("tools/=foo\n", 1), ("tools/=foo\ntools/=foo", 2), ("", 0), (None, 0)