Skip to content

Commit a6c9bc4

Browse files
authored
Handle prefix match with zeros at end of prefix correctly (#674)
This matches the versions appropriately. Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com>
1 parent 7722044 commit a6c9bc4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/packaging/specifiers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
399399
# We need special logic to handle prefix matching
400400
if spec.endswith(".*"):
401401
# In the case of prefix matching we want to ignore local segment.
402-
normalized_prospective = canonicalize_version(prospective.public)
402+
normalized_prospective = canonicalize_version(
403+
prospective.public, strip_trailing_zero=False
404+
)
403405
# Get the normalized version string ignoring the trailing .*
404406
normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
405407
# Split the spec out by dots, and pretend that there is an implicit

tests/test_specifiers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ def test_comparison_non_specifier(self):
369369
("2!1.0", "==2!1.*"),
370370
("2!1.0", "==2!1.0"),
371371
("2!1.0", "!=1.0"),
372+
("2!1.0.0", "==2!1.0.*"),
373+
("2!1.0.0", "==2!1.*"),
372374
("1.0", "!=2!1.0"),
373375
("1.0", "<=2!0.1"),
374376
("2!1.0", ">=2.0"),

0 commit comments

Comments
 (0)