diff --git a/bumpversion/autocast.py b/bumpversion/autocast.py index 06fd0ecb..f417b1aa 100644 --- a/bumpversion/autocast.py +++ b/bumpversion/autocast.py @@ -43,11 +43,14 @@ def listify(s: str) -> list: Returns: List of homogenous basic types. """ - if "," not in s and "\n" not in s: + if "\n" in s: + str_list = s.strip().split("\n") + elif "," in s: + str_list = s.strip().split(",") + else: raise ValueError("Not a List") # derive the type of the variable - str_list = s.strip().split(",") if "," in s else s.strip().split("\n") element_caster = str for caster in (boolify, int, float, noneify, element_caster): with contextlib.suppress(ValueError): diff --git a/tests/fixtures/legacy_multiline_search_comma.cfg b/tests/fixtures/legacy_multiline_search_comma.cfg new file mode 100644 index 00000000..d405c298 --- /dev/null +++ b/tests/fixtures/legacy_multiline_search_comma.cfg @@ -0,0 +1,8 @@ +[bumpversion] +current_version = 1.0.0 + +[bumpversion:file:MULTILINE_SEARCH.md] +search = **unreleased**, + **v{current_version}**, +replace = **unreleased**, + **v{new_version}**, diff --git a/tests/fixtures/legacy_multiline_search_comma_expected.json b/tests/fixtures/legacy_multiline_search_comma_expected.json new file mode 100644 index 00000000..e7fdc5f7 --- /dev/null +++ b/tests/fixtures/legacy_multiline_search_comma_expected.json @@ -0,0 +1,11 @@ +{ + "current_version": "1.0.0", + "files": [ + { + "filename": "MULTILINE_SEARCH.md", + "search": "**unreleased**,\n**v{current_version}**,", + "replace": "**unreleased**,\n**v{new_version}**," + } + ], + "parts": {} +} diff --git a/tests/test_autocast.py b/tests/test_autocast.py index 28204ad8..d3d92a4b 100644 --- a/tests/test_autocast.py +++ b/tests/test_autocast.py @@ -46,6 +46,7 @@ def test_noneify(): param("1,2,3,4", [1, 2, 3, 4], id="int"), param("1\n2\n3\n4", [1, 2, 3, 4], id="int"), param("s,t,r", ["s", "t", "r"], id="str"), + param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str_newline"), param("1.1,2,3.14", [1.1, 2.0, 3.14], id="float"), param("True,False,true,false", [True, False, True, False], id="bool"), param("None,None,None", [None, None, None], id="none"), @@ -75,6 +76,7 @@ def test_listify_invalid(): param("False", False, id="False"), param("1,2,3,4", [1, 2, 3, 4], id="int-list"), param("s,t,r", ["s", "t", "r"], id="str-list"), + param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str-list-newline"), param("1", 1, id="int"), param("1.0", 1.0, id="float"), param(1, 1, id="real-int"), diff --git a/tests/test_config/test_files_legacy.py b/tests/test_config/test_files_legacy.py index a0e0b025..53a95e00 100644 --- a/tests/test_config/test_files_legacy.py +++ b/tests/test_config/test_files_legacy.py @@ -35,6 +35,11 @@ def cfg_file(request) -> str: [ param("basic_cfg.cfg", "basic_cfg_expected.json", id="ini basic cfg"), param("legacy_multiline_search.cfg", "legacy_multiline_search_expected.json", id="multiline search cfg"), + param( + "legacy_multiline_search_comma.cfg", + "legacy_multiline_search_comma_expected.json", + id="multiline search comma cfg", + ), ], ) def test_read_ini_file(conf_file: str, expected_file: str, fixtures_path: Path) -> None: