Skip to content

parse_wheel_filename can return a project name that fails is_normalized_name #1350

Description

@sbidoul

Currently, is_normalized_name only accepts ascii characters:

_normalized_regex = re.compile(r"[a-z0-9]+(?:-[a-z0-9]+)*", re.ASCII)

On the other hand, the wheel specification explicitly says The archive filename is Unicode. It will be some time before the tools are updated to support non-ASCII filenames, but they are supported in this specification.

parse_wheel_filename, following that spec, accepts unicode alphanumeric characters:

_wheel_name_regex = re.compile(r"^[\w._]+\Z", re.UNICODE)

However, while parse_wheel_filename is typed to return NormalizedName and it uses canonicalize_name, it can return names that fail is_normalized_name.

Example:

>>> from packaging.utils import is_normalized_name, canonicalize_name, parse_wheel_filename
>>> name, _, _, _ = parse_wheel_filename("foo_bÁr-1.0-py3-none-any.whl")
>>> name
'foo-bár'
>>> is_normalized_name(name)
False

Should is_normalized_name accept non-ascii alphanumeric characters? Or something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions