From 6434f9866f760981a18d89c284a334051926d4ec Mon Sep 17 00:00:00 2001 From: Stephen Mackenzie Date: Mon, 11 Mar 2024 19:42:10 -0400 Subject: [PATCH] Support leading zeroes in prerelease when using coerce --- semantic_version/base.py | 2 ++ tests/test_base.py | 1 + 2 files changed, 3 insertions(+) diff --git a/semantic_version/base.py b/semantic_version/base.py index 6be5624..f556353 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -295,6 +295,8 @@ def coerce(cls, version_string, partial=False): build = build.replace('+', '.') if prerelease: + if prerelease.startswith("0"): + prerelease = prerelease.lstrip("0") or "0" version = '%s-%s' % (version, prerelease) if build: version = '%s+%s' % (version, build) diff --git a/tests/test_base.py b/tests/test_base.py index 4136045..8ce205a 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -607,6 +607,7 @@ def subTest(self, **kwargs): # Dict of target: [list of equivalents] '0.0.0': ('0', '0.0', '0.0.0', '0.0.0+', '0-'), '0.1.0': ('0.1', '0.1+', '0.1-', '0.1.0', '0.01.0', '000.0001.0000000000'), + '0.1.0-0': ('0.1.0-000'), '0.1.0+2': ('0.1.0+2', '0.1.0.2'), '0.1.0+2.3.4': ('0.1.0+2.3.4', '0.1.0+2+3+4', '0.1.0.2+3+4'), '0.1.0+2-3.4': ('0.1.0+2-3.4', '0.1.0+2-3+4', '0.1.0.2-3+4', '0.1.0.2_3+4'),