Skip to content

Commit

Permalink
Fix handling pre-1.0.0 caret versions (Closes #35)
Browse files Browse the repository at this point in the history
Thanks to @autopulated for pointing the issue!
  • Loading branch information
rbarrois committed Feb 21, 2016
1 parent 9872b39 commit d10ab4c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
ChangeLog
=========


2.5.1 (master)
--------------

*Bugfix:*

* `#35 <https://github.com/rbarrois/python-semanticversion/issues/35>`_:
Properly handle `^0.X.Y` in a NPM-compatible way

2.5.0 (2016-02-12)
------------------

Expand Down
8 changes: 7 additions & 1 deletion semantic_version/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,13 @@ def match(self, version):
elif self.kind == self.KIND_NEQ:
return version != self.spec
elif self.kind == self.KIND_CARET:
return self.spec <= version < self.spec.next_major()
if self.spec.major != 0:
upper = self.spec.next_major()
elif self.spec.minor != 0:
upper = self.spec.next_minor()
else:
upper = self.spec.next_patch()
return self.spec <= version < upper
elif self.kind == self.KIND_TILDE:
return self.spec <= version < self.spec.next_minor()
else: # pragma: no cover
Expand Down
8 changes: 8 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ def test_components(self):
['1.1.3', '1.2.1', '1.1.2-alpha', '1.1.2-alpha+b1'],
['1.1.1', '2.1.0'],
),
'^0.1.2': (
['0.1.2', '0.1.2-alpha', '0.1.3'],
['0.2.0', '1.1.2', '0.1.1'],
),
'^0.0.2': (
['0.0.2', '0.0.2-alpha', '0.0.2+abb'],
['0.1.0', '0.0.3', '1.0.0'],
),
}

def test_matches(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MatchTestCase(unittest.TestCase):
'0.1.2',
'0.1.2+build4.5',
'0.1.3-rc1.3',
'0.2.0',
'0.1.4',
],
'~0.1.2': [
'0.1.2',
Expand Down

0 comments on commit d10ab4c

Please sign in to comment.