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 5d7f020 commit fbfe7d7
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 @@ -399,7 +399,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 fbfe7d7

Please sign in to comment.