Skip to content

Commit

Permalink
fix(mac): normalize filename to NFD form (#7901)
Browse files Browse the repository at this point in the history
  • Loading branch information
jebibot committed Nov 27, 2023
1 parent 3b3a698 commit f83f05f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
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 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {

// 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
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
}

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

0 comments on commit f83f05f

Please sign in to comment.