Skip to content

Arbitrary equality parsed different using Specifer and SpecifierSet #1000

@BarakKatzir

Description

@BarakKatzir

I noticed a difference between how Sepcifier and SpecifierSet parses the arbitrary equality.
The Specifier's regex accepts almost any character, including commas:

[^\s;)]* # The arbitrary version can be just about anything,

This can lead to funky results such as:

>>> from packaging.specifiers import Specifier, SpecifierSet
>>> spec = Specifier('===hello,')
>>> spec_set1 = SpecifierSet([spec])
>>> spec_set2 = SpecifierSet('===hello,')
>>> # both seem identical but are not equal
>>> print(repr(spec_set1))
<SpecifierSet('===hello,')>
>>> print(repr(spec_set2))
<SpecifierSet('===hello')>
>>> assert spec_set1 != spec_set2

Or if the user is not careful, two specifier are parsed as a single arbitrary equality specifier:

>>> Specifier('===moo,<=0.1')
<Specifier('===moo,<=0.1')>
>>> _.operator
'==='

I'm not sure I understand the specification (for version specifiers) correctly, but I expected that arbitrary equality values would not be allowed to contain commas. I think this is a bug, but I'm not sure.

The commas are handled here:

split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()]

I checked this behavior on packaging version 25.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions