Skip to content

Commit 2ece89a

Browse files
authored
fix(msi): manually escape XML special characters when building project.wxs XML (#6878)
1 parent 13b078a commit 2ece89a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.changeset/flat-donkeys-cough.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
Fix MSI build target to support ampersands in the product name

packages/app-builder-lib/src/targets/MsiTarget.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export default class MsiTarget extends Target {
211211
// since RegistryValue can be part of Component, *** *** *** *** *** *** *** *** *** wix cannot auto generate guid
212212
// https://stackoverflow.com/questions/1405100/change-my-component-guid-in-wix
213213
let result = `<Component${directoryId === null ? "" : ` Directory="${directoryId}"`}>`
214-
result += `\n${fileSpace} <File Name="${fileName}" Source="$(var.appDir)${path.sep}${packagePath}" ReadOnly="yes" KeyPath="yes"`
214+
result += `\n${fileSpace} <File Name="${xmlAttr(fileName)}" Source="$(var.appDir)${path.sep}${xmlAttr(packagePath)}" ReadOnly="yes" KeyPath="yes"`
215215
const isMainExecutable = packagePath === `${appInfo.productFilename}.exe`
216216
if (isMainExecutable) {
217217
result += ' Id="mainExecutable"'
@@ -224,7 +224,7 @@ export default class MsiTarget extends Target {
224224
result += `>\n`
225225
const shortcutName = commonOptions.shortcutName
226226
if (isCreateDesktopShortcut) {
227-
result += `${fileSpace} <Shortcut Id="desktopShortcut" Directory="DesktopFolder" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${this.iconId}"/>\n`
227+
result += `${fileSpace} <Shortcut Id="desktopShortcut" Directory="DesktopFolder" Name="${xmlAttr(shortcutName)}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${this.iconId}"/>\n`
228228
}
229229

230230
const hasMenuCategory = commonOptions.menuCategory != null
@@ -233,8 +233,8 @@ export default class MsiTarget extends Target {
233233
if (hasMenuCategory) {
234234
dirs.push(`<Directory Id="${startMenuShortcutDirectoryId}" Name="ProgramMenuFolder:\\${commonOptions.menuCategory}\\"/>`)
235235
}
236-
result += `${fileSpace} <Shortcut Id="startMenuShortcut" Directory="${startMenuShortcutDirectoryId}" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${this.iconId}">\n`
237-
result += `${fileSpace} <ShortcutProperty Key="System.AppUserModel.ID" Value="${this.packager.appInfo.id}"/>\n`
236+
result += `${fileSpace} <Shortcut Id="startMenuShortcut" Directory="${startMenuShortcutDirectoryId}" Name="${xmlAttr(shortcutName)}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${this.iconId}">\n`
237+
result += `${fileSpace} <ShortcutProperty Key="System.AppUserModel.ID" Value="${xmlAttr(this.packager.appInfo.id)}"/>\n`
238238
result += `${fileSpace} </Shortcut>\n`
239239
}
240240
result += `${fileSpace}</File>`
@@ -255,7 +255,7 @@ export default class MsiTarget extends Target {
255255
item.description ? `Description="${item.description}"` : ""
256256
}>\n`
257257
result += `${fileSpace} <Extension Id="${ext}" Advertise="yes">\n`
258-
result += `${fileSpace} <Verb Id="open" Command="Open with ${this.packager.appInfo.productName}" Argument="&quot;%1&quot;"/>\n`
258+
result += `${fileSpace} <Verb Id="open" Command="Open with ${xmlAttr(this.packager.appInfo.productName)}" Argument="&quot;%1&quot;"/>\n`
259259
result += `${fileSpace} </Extension>\n`
260260
result += `${fileSpace} </ProgId>\n`
261261
}
@@ -273,3 +273,12 @@ function listToString(list: Array<string>, indentLevel: number) {
273273
const space = " ".repeat(indentLevel * 2)
274274
return list.join(`\n${space}`)
275275
}
276+
277+
function xmlAttr(str: string) {
278+
return str
279+
.replace(/&/g, "&amp;")
280+
.replace(/</g, "&lt;")
281+
.replace(/>/g, "&gt;")
282+
.replace(/"/g, "&quot;")
283+
.replace(/'/g, "&apos;")
284+
}

0 commit comments

Comments
 (0)