From 4bc0edd07fb3210dd382512d6485ef172fcbfb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Wed, 28 Aug 2019 21:09:50 +0200 Subject: Fix NPM-style caret matching. --- semantic_version/base.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'semantic_version') diff --git a/semantic_version/base.py b/semantic_version/base.py index fb8205c..1c4b01d 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -1186,7 +1186,7 @@ class NpmSpec(BaseSpec): PART = r'[a-zA-Z0-9.-]*' NPM_SPEC_BLOCK = re.compile(r""" ^(?:v)? # Strip optional initial v - (?P<|<=|>=|>|=|^|~|) # Operator, can be empty + (?P<|<=|>=|>|=|\^|~|) # Operator, can be empty (?P{nb})(?:\.(?P{nb})(?:\.(?P{nb}))?)? (?:-(?P{part}))? # Optional re-release (?:\+(?P{part}))? # Optional build @@ -1316,13 +1316,17 @@ class NpmSpec(BaseSpec): raise ValueError("Invalid NPM spec: %r" % simple) if prefix == cls.PREFIX_CARET: - if target.major: # ^1.2.4 => >=1.2.4 <2.0.0 - high = target.next_major() + if target.major: # ^1.2.4 => >=1.2.4 <2.0.0 ; ^1.x => >=1.0.0 <2.0.0 + high = target.truncate().next_major() elif target.minor: # ^0.1.2 => >=0.1.2 <0.2.0 - high = target.next_minor() + high = target.truncate().next_minor() + elif minor is None: # ^0.x => >=0.0.0 <1.0.0 + high = target.truncate().next_major() + elif patch is None: # ^0.2.x => >=0.2.0 <0.3.0 + high = target.truncate().next_minor() else: # ^0.0.1 => >=0.0.1 <0.0.2 - high = target.next_patch() - return [cls.range(Range.OP_GTE, target), cls.Range(Range.OP_LT, high)] + high = target.truncate().next_patch() + return [cls.range(Range.OP_GTE, target), cls.range(Range.OP_LT, high)] elif prefix == cls.PREFIX_TILDE: assert major is not None -- cgit v1.2.1