summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2016-02-21 18:54:02 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2016-02-21 18:54:02 +0100
commitd10ab4cb1d1ca8090132f205017dfc90473c91cc (patch)
tree7924515805bcfb6960d28c59ea7425452db14f3a
parent9872b3940e87d1d810560ea4381929554fd8038c (diff)
downloadsemantic-version-d10ab4cb1d1ca8090132f205017dfc90473c91cc.tar.gz
Fix handling pre-1.0.0 caret versions (Closes #35)
Thanks to @autopulated for pointing the issue!
-rw-r--r--ChangeLog9
-rw-r--r--semantic_version/base.py8
-rwxr-xr-xtests/test_base.py8
-rwxr-xr-xtests/test_match.py2
4 files changed, 25 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 423e3bd..7352663 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
------------------
diff --git a/semantic_version/base.py b/semantic_version/base.py
index 8877dbf..1504642 100644
--- a/semantic_version/base.py
+++ b/semantic_version/base.py
@@ -459,7 +459,13 @@ class SpecItem(object):
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
diff --git a/tests/test_base.py b/tests/test_base.py
index 1fcce8c..24bf86e 100755
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -506,6 +506,14 @@ class SpecItemTestCase(unittest.TestCase):
['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):
diff --git a/tests/test_match.py b/tests/test_match.py
index f0b0fe8..49464f8 100755
--- a/tests/test_match.py
+++ b/tests/test_match.py
@@ -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',