Skip to content
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

Fix minor holes in PEP-508 name validation #1762

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1762.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When creating a new project, the validation for App Name now rejects all non-ASCII values.
8 changes: 6 additions & 2 deletions src/briefcase/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
from .constants import RESERVED_WORDS
from .exceptions import BriefcaseConfigError

# PEP508 provides a basic restriction on naming
PEP508_NAME_RE = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.IGNORECASE)
# PEP 508 restricts the naming of modules. The PEP defines a regex that uses
# re.IGNORECASE; but in in practice, packaging uses a version that rolls out the lower
# case, which has very slightly different semantics with non-ASCII characters. This
# definition is the one from
# https://github.com/pypa/packaging/blob/24.0/src/packaging/_tokenizer.py#L80
PEP508_NAME_RE = re.compile(r"^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])$")


def is_valid_pep508_name(app_name):
Expand Down
1 change: 0 additions & 1 deletion tests/commands/new/test_validate_app_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"42helloworld", # ?? Are we sure this is correct?
"hello_world",
"hello-world",
"helloworld_ı",
],
)
def test_valid_app_name(new_command, name):
Expand Down
6 changes: 6 additions & 0 deletions tests/config/test_is_valid_app_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def test_is_valid_app_name(name):
"main",
"socket",
"test",
# ı, İ and K (i.e. 0x212a) are valid ASCII when made lowercase and as such are
# accepted by the official PEP 508 regex... but they are rejected here to ensure
# compliance with the regex that is used in practice.
"helloworld_ı",
"İstanbul",
"Kelvin",
],
)
def test_is_invalid_app_name(name):
Expand Down
Loading