Skip to content

Commit

Permalink
Handle prefix match with zeros at end of prefix correctly (#674)
Browse files Browse the repository at this point in the history
This matches the versions appropriately.

Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com>
  • Loading branch information
pradyunsg and pradyunsg committed Feb 3, 2023
1 parent 7722044 commit a6c9bc4
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
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
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 a6c9bc4

Please sign in to comment.