Skip to content

Conversation

@dev-adas
Copy link

This addresses #2071 (details were also left on this comment #2071 (comment))

Formal Names with a double quote was causing invalid strings, this was causing the post_gen_project hook for MacOS to fail.

Log error:

Using app template: https://github.com/beeware/briefcase-macOS-app-template.git, branch v0.3.23
Cloning template 'https://github.com/beeware/briefcase-macOS-app-template.git'...
Using existing template (sha f63353430d7c94e2efd4164c9dcd526ba5d03b5e, updated Thu Apr 17 13:23:14 2025)
  File "/var/folders/_p/5_kmj5r5145_n0410jzn6_xh0000gn/T/tmpcb7a8dh2.py", line 12
    INFO_PATH = Path("badFormalName".app/Contents/Info.plist")
                                                         ^
SyntaxError: unterminated string literal (detected at line 12)
Stopping generation because post_gen_project hook script didn't exit successfully

One proposed solution was to make the "fix" with {{ cookiecutter.formal_name|replace('"', '\\"') }} on line 12 of the macOS post gen template script

However, fixing this caused cascading issues (invalid strings) with the generation of the briefcase.toml corresponding to the user's application build.

See example for formal_name as badFormalName"

# Generated using Python 3.13.3
[briefcase]
# This is the start of the framework-based support package era.
target_version = "0.3.20"

[paths]
app_path = "badFormalName".app/Contents/Resources/app"
app_packages_path = "badFormalName".app/Contents/Resources/app_packages"
info_plist_path = "badFormalName".app/Contents/Info.plist"
entitlements_path = "Entitlements.plist"
support_path = "badFormalName".app/Contents/Frameworks"
runtime_path = "Python.xcframework/macos-arm64_x86_64/Python.framework"
support_revision = 6
stub_binary_revision = 11
cleanup_paths = [
    "badFormalName".app/Contents/Frameworks/Python.framework/**/Headers",
    "badFormalName".app/Contents/Frameworks/Python.framework/**/include",
    "badFormalName".app/Contents/Frameworks/Python.framework/**/config-*-darwin",
    "badFormalName".app/Contents/Frameworks/Python.framework/**/pkg-config",
]
icon = "badFormalName".app/Contents/Resources/badFormalName.icns"

Solution:
Do not allow users to create an application with a formal name containing a double quote(s).

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in person - we can't eliminate this at the level of the new wizard - in part because the new wizard is only one place for a formal name to be specified, but also because a quote is a valid formal name.

What we need here is more complete escaping across the board; but we can't do that on the Briefcase side, because the escaping used depends on the context in which the values is used.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - but it requires a test case to verify against future regressions.

Co-authored-by: Russell Keith-Magee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants