summaryrefslogtreecommitdiff
path: root/semantic_version
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2019-12-21 15:51:24 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2019-12-21 16:02:12 +0100
commit2fb427d0d9d9c70d08a707c6fb5bcc2ae2c4023b (patch)
tree907ba3bd46e10f6be9deed1d1d2d48a853b16808 /semantic_version
parent25db2464933444f7d332edba94bcee48fa8c0793 (diff)
downloadsemantic-version-2fb427d0d9d9c70d08a707c6fb5bcc2ae2c4023b.tar.gz
Properly coerce versions with leading zeroes.
A leading zero is forbidden in the SemVer spec, but could be valid under other schemes; when coercing, it can easily be removed. Closes #89, thanks to Andrew Ni for the report.
Diffstat (limited to 'semantic_version')
-rw-r--r--semantic_version/base.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/semantic_version/base.py b/semantic_version/base.py
index 1b0bac5..7fd871e 100644
--- a/semantic_version/base.py
+++ b/semantic_version/base.py
@@ -244,6 +244,14 @@ class Version(object):
while version.count('.') < 2:
version += '.0'
+ # Strip leading zeros in components
+ # Version is of the form nn, nn.pp or nn.pp.qq
+ version = '.'.join(
+ # If the part was '0', we end up with an empty string.
+ part.lstrip('0') or '0'
+ for part in version.split('.')
+ )
+
if match.end() == len(version_string):
return Version(version, partial=partial)