Skip to content

Commit

Permalink
Fix prefix version matching
Browse files Browse the repository at this point in the history
0-padding shall only be applied on the prospective version, before shortening,
in order to get the correct shortened prospective version.
  • Loading branch information
mayeut committed Jun 19, 2022
1 parent 28873f9 commit 740997b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packaging/specifiers.py
Expand Up @@ -450,18 +450,16 @@ def _compare_equal(self, prospective: ParsedVersion, spec: str) -> bool:
# segment.
split_prospective = _version_split(str(prospective))

# 0-pad the prospective version before shortening it to get the correct
# shortened version.
padded_prospective, _ = _pad_version(split_prospective, split_spec)

# Shorten the prospective version to be the same length as the spec
# so that we can determine if the specifier is a prefix of the
# prospective version or not.
shortened_prospective = split_prospective[: len(split_spec)]

# Pad out our two sides with zeros so that they both equal the same
# length.
padded_spec, padded_prospective = _pad_version(
split_spec, shortened_prospective
)
shortened_prospective = padded_prospective[: len(split_spec)]

return padded_prospective == padded_spec
return shortened_prospective == split_spec
else:
# Convert our spec string into a Version
spec_version = Version(spec)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_specifiers.py
Expand Up @@ -314,8 +314,11 @@ def test_comparison_non_specifier(self):
("2b1.dev1", "==2.*"),
("2c1", "==2.*"),
("2c1.post1.dev1", "==2.*"),
("2c1.post1.dev1", "==2.0.*"),
("2rc1", "==2.*"),
("2rc1", "==2.0.*"),
("2", "==2.*"),
("2", "==2.0.*"),
("2", "==0!2.*"),
("0!2", "==2.*"),
("2.0", "==2.*"),
Expand Down Expand Up @@ -411,8 +414,11 @@ def test_comparison_non_specifier(self):
("2b1.dev1", "!=2.*"),
("2c1", "!=2.*"),
("2c1.post1.dev1", "!=2.*"),
("2c1.post1.dev1", "!=2.0.*"),
("2rc1", "!=2.*"),
("2rc1", "!=2.0.*"),
("2", "!=2.*"),
("2", "!=2.0.*"),
("2.0", "!=2.*"),
("2.0.0", "!=2.*"),
# Test the greater than equal operation
Expand Down

0 comments on commit 740997b

Please sign in to comment.