Giving a formal name with a character such as ', /, \, causes briefcase new to crash
mfreydavis opened this issue · comments
Describe the bug
When you execute briefcase new
and set the name to / you get an IndexError: string index out of range.
This is also true for some other characters such as /, \ , ", ', and ,
It appears to effect all of that class of characters due to the way the class name is created.
The problem appears to be in config.py make_class_name:
# Normalize to NFKC form, then remove any character that isn't
# in the allowed categories, or is the underscore character;
# Capitalize the resulting word.
class_name = "".join(
ch
for ch in unicodedata.normalize("NFKC", formal_name)
if unicodedata.category(ch) in xid_continue or ch in {"_"}
)
This causes the name to be stripped of all characters, making the string length zero.
This causes an attempt to make a class name to fail
# If the first character isn't in the 'start' character set,
# and it isn't already an underscore, prepend an underscore.
if unicodedata.category(class_name[0]) not in xid_start and class_name[0] != "_":
class_name = f"_{class_name}"
return class_name
Steps to reproduce
- Run
briefcase new
- When prompted Formal Name [Hello World]: enter \
Expected behavior
Validation should force you to create a legal name, or additionally prompt you to create proper class names.
Screenshots
No response
Environment
- Operating System: Linux
- Python version: 3.11
- Software versions:
- Briefcase: 0.3.19.dev26+g96734be6.d20240520
- Toga:
- ...
Logs
No response
Additional context
No response
I'm looking into this
I have a fix developed. Essentially added a validator function to the input. Working on the pull request process now.