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(mac): normalize filename to NFD form #7901

Merged
merged 2 commits into from
Nov 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-flowers-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix codesign and DMG layout when productName or executableName contains Unicode
11 changes: 8 additions & 3 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export class AppInfo {
readonly sanitizedProductName: string
readonly productFilename: string

constructor(private readonly info: Packager, buildVersion: string | null | undefined, private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null) {
constructor(
private readonly info: Packager,
buildVersion: string | null | undefined,
private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null,
normalizeNfd = false
) {
this.version = info.metadata.version!

if (buildVersion == null) {
Expand Down Expand Up @@ -63,10 +68,10 @@ export class AppInfo {
}

this.productName = info.config.productName || info.metadata.productName || info.metadata.name!
this.sanitizedProductName = sanitizeFileName(this.productName)
this.sanitizedProductName = sanitizeFileName(this.productName, normalizeNfd)

const executableName = platformSpecificOptions?.executableName ?? info.config.executableName
this.productFilename = executableName != null ? sanitizeFileName(executableName) : this.sanitizedProductName
this.productFilename = executableName != null ? sanitizeFileName(executableName, normalizeNfd) : this.sanitizedProductName
}

get channel(): string | null {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected prepareAppInfo(appInfo: AppInfo): AppInfo {
return new AppInfo(this.info, this.platformSpecificBuildOptions.bundleVersion, this.platformSpecificBuildOptions)
// codesign requires the filename to be normalized to the NFD form
return new AppInfo(this.info, this.platformSpecificBuildOptions.bundleVersion, this.platformSpecificBuildOptions, true)
}

async getIconPath(): Promise<string | null> {
Expand Down Expand Up @@ -562,7 +563,7 @@
}
if (notaryToolLogin) {
return {
tool: 'notarytool',

Check warning on line 566 in packages/app-builder-lib/src/macPackager.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `'notarytool'` with `"notarytool"`

Check warning on line 566 in packages/app-builder-lib/src/macPackager.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `'notarytool'` with `"notarytool"`
appPath,
...notaryToolLogin,
}
Expand Down
5 changes: 3 additions & 2 deletions packages/app-builder-lib/src/util/filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import * as _sanitizeFileName from "sanitize-filename"
import * as path from "path"

export function sanitizeFileName(s: string): string {
return _sanitizeFileName(s)
export function sanitizeFileName(s: string, normalizeNfd = false): string {
const sanitized = _sanitizeFileName(s)
return normalizeNfd ? sanitized.normalize("NFD") : sanitized
mmaietta marked this conversation as resolved.
Show resolved Hide resolved
}

// Get the filetype from a filename. Returns a string of one or more file extensions,
Expand Down