Skip to content

Commit 50a5fd6

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 e404434 commit 50a5fd6

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
@@ -381,9 +381,12 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
381381
if spec.endswith(".*"):
382382
# In the case of prefix matching we want to ignore local segment.
383383
prospective = Version(prospective.public)
384+
# Convert our spec string into a Version ignoring the trailing .*
385+
# This allows to get the normalized version string
386+
spec_version = Version(spec[:-2])
384387
# Split the spec out by dots, and pretend that there is an implicit
385388
# dot in between a release segment and a pre-release segment.
386-
split_spec = _version_split(spec[:-2]) # Remove the trailing .*
389+
split_spec = _version_split(str(spec_version))
387390

388391
# Split the prospective version out by dots, and pretend that there
389392
# 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)