Skip to content

Commit

Permalink
Merge pull request #1762 from rmartin16/pep508
Browse files Browse the repository at this point in the history
Fix minor holes in PEP-508 name validation
  • Loading branch information
freakboy3742 authored Apr 30, 2024
2 parents fcfb108 + ca10e55 commit e43a9f4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
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

0 comments on commit e43a9f4

Please sign in to comment.