-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version
and Specifier
accept (erroneously) some non-ASCII letters in the *local version* segment
#469
Comments
The whitespace issue can probably be worked around by doing that detection separately from the actual parsing. class Version:
_regex = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE | re.ASCII)
def __init__(self, version: str) -> None:
match = self._regex.match(version.strip())
# ... The rest is the same ... |
Version
accepts (erroneously) some non-ASCII letters in the local
partVersion
and Specifier
accept (erroneously) some non-ASCII letters in the *local version* segment
Reproducing the behavior concerning Python 3.9.7 (default, Oct 4 2021, 18:09:29)
[...]
>>> import packaging.specifiers
>>> packaging.specifiers.Specifier('==1.2+\u0130\u0131\u017f\u212a')
<Specifier('==1.2+İıſK')> The cause is the same as the aforementioned In the case of these regexes, Instead of that, an additional check can be performed when the operator is not without_whitespace = ''.join(spec.split())
if not without_whitespace.isascii():
raise InvalidSpecifier... |
* Fix validation in the packaging.version.Version's constructor * Fix validation in the packaging.specifiers.Specifier's constructor * Fix docs of packaging.version.VERSION_PATTERN by mentioning necessity of the re.ASCII flag
* Fix validation in the packaging.version.Version's constructor * Fix validation in the packaging.specifiers.Specifier's constructor * Fix docs of packaging.version.VERSION_PATTERN by mentioning necessity of the re.ASCII flag
* Fix validation in the packaging.version.Version's constructor * Fix validation in the packaging.specifiers.Specifier's constructor * Fix docs of packaging.version.VERSION_PATTERN by mentioning necessity of the re.ASCII flag
* Fix validation in the packaging.version.Version's constructor * Fix validation in the packaging.specifiers.Specifier's constructor * Complement relevant tests, including adding cases related to presence of non-ASCII whitespace characters in input strings * Fix docs of packaging.version.VERSION_PATTERN by mentioning necessity of the re.ASCII flag
Reproducing the behavior concerning
packaging.version.Version
:The cause is that
packaging.version.VERSION_PATTERN
makes use ofa-z
character ranges in conjunction withre.IGNORECASE
and (implicit in Python 3.x)re.UNICODE
(see the 2nd paragraph of this fragment: https://docs.python.org/3/library/re.html#re.IGNORECASE).It can be fixed in one of the following two ways:
re.ASCII
to flags (but then both occurrences of\s*
in the actual regex will be restricted to match ASCII-only whitespace characters!);re.IGNORECASE
from flags and replacing (inVERSION_PATTERN
) both occurrences ofa-z
withA-Za-z
plus adding suitable upper-case alternatives in thepre_l
,post_l
anddev_l
regex groups, e.g.,[aA][lL][pP][hH][aA]
in place ofalpha
(quite cumbersome...).The text was updated successfully, but these errors were encountered: