Skip to content

Commit b8ea252

Browse files
committed
Fix miscast of current_version
- When using the legacy configuration format, a single-digit version is parsed as an int Fixes #99
1 parent 5232255 commit b8ea252

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

bumpversion/config/files_legacy.py

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def read_ini_file(file_path: Path) -> Dict[str, Any]: # noqa: C901
4343
section_parts = section_name.split(":")
4444
num_parts = len(section_parts)
4545
options = {key: autocast.autocast_value(val) for key, val in config_parser.items(section_name)}
46+
if "current_version" in options:
47+
options["current_version"] = str(options["current_version"])
4648

4749
if num_parts == 1: # bumpversion section
4850
bumpversion_options.update(options)

tests/test_config/test_files_legacy.py

+19
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,22 @@ def test_utf8_message_from_config_file(tmp_path: Path, cfg_file):
148148
cfg = config.get_configuration(cfg_path)
149149

150150
assert cfg.message == "Nová verze: {current_version} ☃, {new_version} ☀"
151+
152+
153+
def test_current_version_is_always_a_string(tmp_path: Path):
154+
cfg_path = tmp_path / ".bumpversion.cfg"
155+
initial_config = (
156+
"[bumpversion]\n"
157+
"current_version = 2\n"
158+
"commit = False\n"
159+
"tag = False\n"
160+
"parse = (?P<major>\d+)\n"
161+
"serialize = \n"
162+
" {major}\n"
163+
)
164+
cfg_path.write_bytes(initial_config.encode("utf-8"))
165+
166+
with inside_dir(tmp_path):
167+
cfg = config.get_configuration(cfg_path)
168+
169+
assert cfg.current_version == "2"

0 commit comments

Comments
 (0)