Skip to content

Commit 5e5932c

Browse files
committed
Normalize specifier version for prefix matching
In case of prefix version matching, normalization of the version was not applied to the specifier's version. This resulted in `2` being rejected as a candidate for `==0!2.*` With normalization applied, the candidate is now accepted.
1 parent 237ff3a commit 5e5932c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packaging/specifiers.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
266266
if spec.endswith(".*"):
267267
# In the case of prefix matching we want to ignore local segment.
268268
prospective = Version(prospective.public)
269+
# Convert our spec string into a Version ignoring the trailing .*
270+
# This allows to get the normalized version string
271+
spec_version = Version(spec[:-2])
269272
# Split the spec out by dots, and pretend that there is an implicit
270273
# dot in between a release segment and a pre-release segment.
271-
split_spec = _version_split(spec[:-2]) # Remove the trailing .*
274+
split_spec = _version_split(str(spec_version))
272275

273276
# Split the prospective version out by dots, and pretend that there
274277
# is an implicit dot in between a release segment and a pre-release

tests/test_specifiers.py

+4
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,14 @@ def test_comparison_non_specifier(self):
302302
("2c1.post1.dev1", "==2.*"),
303303
("2rc1", "==2.*"),
304304
("2", "==2.*"),
305+
("2", "==0!2.*"),
306+
("0!2", "==2.*"),
305307
("2.0", "==2.*"),
306308
("2.0.0", "==2.*"),
307309
("2.0.post1", "==2.0.post1.*"),
308310
("2.0.post1.dev1", "==2.0.post1.*"),
311+
("2.0.rc1", "==2.0.c1.*"),
312+
("2.0.rc1.post1", "==2.0.c1.*"),
309313
("2.1+local.version", "==2.1.*"),
310314
# Test the in-equality operation
311315
("2.1", "!=2"),

0 commit comments

Comments
 (0)