Skip to content

Commit

Permalink
Merge pull request #56358 from s0undt3ch/hotfix/version-parsing
Browse files Browse the repository at this point in the history
Fix version instantiation when minor is an empty string
  • Loading branch information
dwoz authored Mar 11, 2020
2 parents b33047c + cb22e78 commit c6c6e2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions salt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class SaltStackVersion(object):
'Sodium' : (MAX_SIZE - 98, 0),
'Magnesium' : (MAX_SIZE - 97, 0),
'Aluminium' : (MAX_SIZE - 96, 0),
'Silicon' : (MAX_SIZE - 95, 0),
'Phosphorus' : (MAX_SIZE - 94, 0),
'Silicon' : (MAX_SIZE - 95, 0),
'Phosphorus' : (MAX_SIZE - 94, 0),
# pylint: disable=E8265
#'Sulfur' : (MAX_SIZE - 93, 0),
#'Chlorine' : (MAX_SIZE - 92, 0),
Expand Down Expand Up @@ -232,7 +232,11 @@ def __init__(self, # pylint: disable=C0103
major = int(major)

if isinstance(minor, string_types):
minor = int(minor)
if not minor:
# Empty string
minor = None
else:
minor = int(minor)

if bugfix is None and not self.new_version(major=major):
bugfix = 0
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_version_parsing(self):
('v4518.1', (4518, 1, '', 0, 0, None), '4518.1'),
('v3000rc1', (3000, 'rc', 1, 0, None), '3000rc1'),
('v3000rc1-n/a-abcdefff', (3000, 'rc', 1, -1, 'abcdefff'), None),
('3000-n/a-1e7bc8f', (3000, '', 0, -1, '1e7bc8f'), None)

)

Expand Down Expand Up @@ -148,6 +149,27 @@ def test_string_new_version_minor(self):
assert not ver.bugfix
assert ver.string == '{0}.{1}'.format(maj_ver, min_ver)

def test_string_new_version_minor_as_string(self):
'''
Validate string property method
using new versioning scheme alongside
minor version
'''
maj_ver = '3000'
min_ver = '1'
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
assert ver.minor == int(min_ver)
assert not ver.bugfix
assert ver.string == '{0}.{1}'.format(maj_ver, min_ver)

# This only seems to happen on a cloned repo without its tags
maj_ver = '3000'
min_ver = ''
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
assert ver.minor is None, '{!r} is not {!r}'.format(ver.minor, min_ver) # pylint: disable=repr-flag-used-in-string
assert not ver.bugfix
assert ver.string == maj_ver

def test_string_old_version(self):
'''
Validate string property method
Expand Down

0 comments on commit c6c6e2e

Please sign in to comment.