beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.48k stars 352 forks source link

Giving a formal name with a character such as ', /, \, causes briefcase new to crash #1810

Closed mfreydavis closed 1 month ago

mfreydavis commented 1 month ago

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

  1. Run briefcase new
  2. 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

Logs

No response

Additional context

No response

mblahay commented 1 month ago

I'm looking into this

mblahay commented 1 month ago

I have a fix developed. Essentially added a validator function to the input. Working on the pull request process now.