Skip to content

Commit

Permalink
Handle prefix match with zeros at end of prefix correctly
Browse files Browse the repository at this point in the history
This matches the versions appropriately.
  • Loading branch information
pradyunsg committed Jan 31, 2023
1 parent 068a0b5 commit 5f821ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
# We need special logic to handle prefix matching
if spec.endswith(".*"):
# In the case of prefix matching we want to ignore local segment.
normalized_prospective = canonicalize_version(prospective.public)
normalized_prospective = canonicalize_version(
prospective.public, strip_trailing_zero=False
)
# Get the normalized version string ignoring the trailing .*
normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
# Split the spec out by dots, and pretend that there is an implicit
Expand Down
2 changes: 2 additions & 0 deletions tests/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ def test_comparison_non_specifier(self):
("2!1.0", "==2!1.*"),
("2!1.0", "==2!1.0"),
("2!1.0", "!=1.0"),
("2!1.0.0", "==2!1.0.*"),
("2!1.0.0", "==2!1.*"),
("1.0", "!=2!1.0"),
("1.0", "<=2!0.1"),
("2!1.0", ">=2.0"),
Expand Down

0 comments on commit 5f821ab

Please sign in to comment.