From f7f9cf3152700ef77473cc67f86fcd712aebd7ae Mon Sep 17 00:00:00 2001 From: abergeron Date: Wed, 27 May 2020 12:55:04 -0400 Subject: [PATCH 1/2] Use fullmatch instead of match Using match only matches the beginning of the string and can ignore some version information. I've encountered this problem with this version string '0.7.1dev1+1.*' where not using fullmatch would ignore the '.*' part. --- semver/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/semver/__init__.py b/semver/__init__.py index 2b36cd1..350f56a 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -54,7 +54,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint return VersionRange() # Tilde range - m = TILDE_CONSTRAINT.match(constraint) + m = TILDE_CONSTRAINT.fullmatch(constraint) if m: version = Version.parse(m.group(1)) @@ -67,7 +67,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # PEP 440 Tilde range (~=) - m = TILDE_PEP440_CONSTRAINT.match(constraint) + m = TILDE_PEP440_CONSTRAINT.fullmatch(constraint) if m: precision = 1 if m.group(3): @@ -90,7 +90,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # Caret range - m = CARET_CONSTRAINT.match(constraint) + m = CARET_CONSTRAINT.fullmatch(constraint) if m: version = Version.parse(m.group(1)) @@ -102,7 +102,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # X Range - m = X_CONSTRAINT.match(constraint) + m = X_CONSTRAINT.fullmatch(constraint) if m: op = m.group(1) major = int(m.group(2)) @@ -136,7 +136,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint return result # Basic comparator - m = BASIC_CONSTRAINT.match(constraint) + m = BASIC_CONSTRAINT.fullmatch(constraint) if m: op = m.group(1) version = m.group(2) From 65435c7c351e7b44106265eae9157df3e3680bf2 Mon Sep 17 00:00:00 2001 From: Arnaud Bergeron Date: Sat, 30 May 2020 17:40:14 -0400 Subject: [PATCH 2/2] Use a final $ instead of fullmatch() for python 2.7 compat --- semver/__init__.py | 10 +++++----- semver/patterns.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/semver/__init__.py b/semver/__init__.py index 350f56a..2b36cd1 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -54,7 +54,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint return VersionRange() # Tilde range - m = TILDE_CONSTRAINT.fullmatch(constraint) + m = TILDE_CONSTRAINT.match(constraint) if m: version = Version.parse(m.group(1)) @@ -67,7 +67,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # PEP 440 Tilde range (~=) - m = TILDE_PEP440_CONSTRAINT.fullmatch(constraint) + m = TILDE_PEP440_CONSTRAINT.match(constraint) if m: precision = 1 if m.group(3): @@ -90,7 +90,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # Caret range - m = CARET_CONSTRAINT.fullmatch(constraint) + m = CARET_CONSTRAINT.match(constraint) if m: version = Version.parse(m.group(1)) @@ -102,7 +102,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ) # X Range - m = X_CONSTRAINT.fullmatch(constraint) + m = X_CONSTRAINT.match(constraint) if m: op = m.group(1) major = int(m.group(2)) @@ -136,7 +136,7 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint return result # Basic comparator - m = BASIC_CONSTRAINT.fullmatch(constraint) + m = BASIC_CONSTRAINT.match(constraint) if m: op = m.group(1) version = m.group(2) diff --git a/semver/patterns.py b/semver/patterns.py index 63cce54..75944f4 100644 --- a/semver/patterns.py +++ b/semver/patterns.py @@ -11,12 +11,12 @@ MODIFIERS ) -COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION) +COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION + "$") CARET_CONSTRAINT = re.compile(r"(?i)^\^({})$".format(_COMPLETE_VERSION)) TILDE_CONSTRAINT = re.compile("(?i)^~(?!=)({})$".format(_COMPLETE_VERSION)) TILDE_PEP440_CONSTRAINT = re.compile("(?i)^~=({})$".format(_COMPLETE_VERSION)) X_CONSTRAINT = re.compile(r"^(!=|==)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$") BASIC_CONSTRAINT = re.compile( - r"(?i)^(<>|!=|>=?|<=?|==?)?\s*({}|dev)".format(_COMPLETE_VERSION) + r"(?i)^(<>|!=|>=?|<=?|==?)?\s*({}|dev)$".format(_COMPLETE_VERSION) )