From 2dc52ebc7872b1091cb85e594d121e4de80a35b2 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 19 Jun 2022 11:46:25 +0200 Subject: [PATCH] Forbid prefix version matching on pre-release/post-release segments It does not make much sense to have this. Let's forbid it. --- packaging/specifiers.py | 22 +++++++++++----------- tests/test_specifiers.py | 14 ++++++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packaging/specifiers.py b/packaging/specifiers.py index a2d51b04c..be6004db9 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -328,19 +328,19 @@ class Specifier(_IndividualSpecifier): v? (?:[0-9]+!)? # epoch [0-9]+(?:\.[0-9]+)* # release - (?: # pre release - [-_\.]? - (a|b|c|rc|alpha|beta|pre|preview) - [-_\.]? - [0-9]* - )? - (?: # post release - (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) - )? - # You cannot use a wild card and a dev or local version - # together so group them with a | and make them optional. + # You cannot use a wild card and a pre-release, post-release, dev or + # local version together so group them with a | and make them optional. (?: + (?: # pre release + [-_\.]? + (a|b|c|rc|alpha|beta|pre|preview) + [-_\.]? + [0-9]* + )? + (?: # post release + (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) + )? (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local | diff --git a/tests/test_specifiers.py b/tests/test_specifiers.py index 5949ebf61..e99d295b9 100644 --- a/tests/test_specifiers.py +++ b/tests/test_specifiers.py @@ -71,7 +71,14 @@ def test_specifiers_valid(self, specifier): # support one or the other "==1.0.*+5", "!=1.0.*+deadbeef", - # Prefix matching cannot be used inside of a local version + # Prefix matching cannot be used with a pre-release, post-release, + # dev or local version + "==2.0a1.*", + "!=2.0a1.*", + "==2.0.post1.*", + "!=2.0.post1.*", + "==2.0.dev1.*", + "!=2.0.dev1.*", "==1.0+5.*", "!=1.0+deadbeef.*", # Prefix matching must appear at the end @@ -311,8 +318,6 @@ def test_comparison_non_specifier(self): ("2", "==2.*"), ("2.0", "==2.*"), ("2.0.0", "==2.*"), - ("2.0.post1", "==2.0.post1.*"), - ("2.0.post1.dev1", "==2.0.post1.*"), ("2.1+local.version", "==2.1.*"), # Test the in-equality operation ("2.1", "!=2"), @@ -408,8 +413,6 @@ def test_comparison_non_specifier(self): ("2", "!=2.*"), ("2.0", "!=2.*"), ("2.0.0", "!=2.*"), - ("2.0.post1", "!=2.0.post1.*"), - ("2.0.post1.dev1", "!=2.0.post1.*"), # Test the greater than equal operation ("2.0.dev1", ">=2"), ("2.0a1", ">=2"), @@ -535,7 +538,6 @@ def test_specifier_prereleases_detection(self, specifier, expected): (">=1.0", "2.0.dev1", False), (">=2.0.dev1", "2.0a1", True), ("==2.0.*", "2.0a1.dev1", False), - ("==2.0a1.*", "2.0a1.dev1", True), ("<=2.0", "1.0.dev1", False), ("<=2.0.dev1", "1.0a1", True), ],