Skip to content

Commit 6d6b6e6

Browse files
feat: configure escaping on handlebars templates (#6678)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
1 parent 40f137c commit 6d6b6e6

File tree

18 files changed

+290
-120
lines changed

18 files changed

+290
-120
lines changed

.changes/handlebars-escape.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": patch
3+
"cli.rs": patch
4+
"cli.js": patch
5+
---
6+
7+
Use escaping on Handlebars templates.

tooling/bundler/src/bundle/linux/appimage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
8181

8282
// initialize shell script template.
8383
let mut handlebars = Handlebars::new();
84+
handlebars.register_escape_fn(|s| s.into());
8485
handlebars
8586
.register_template_string("appimage", include_str!("templates/appimage"))
8687
.expect("Failed to register template for handlebars");

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ pub fn build_wix_app_installer(
692692

693693
// Create the Powershell script to install the task
694694
let mut skip_uac_task_installer = Handlebars::new();
695+
skip_uac_task_installer.register_escape_fn(|s| s.into());
695696
let xml = include_str!("../templates/install-task.ps1");
696697
skip_uac_task_installer
697698
.register_template_string("install-task.ps1", xml)
@@ -703,6 +704,7 @@ pub fn build_wix_app_installer(
703704

704705
// Create the Powershell script to uninstall the task
705706
let mut skip_uac_task_uninstaller = Handlebars::new();
707+
skip_uac_task_uninstaller.register_escape_fn(|s| s.into());
706708
let xml = include_str!("../templates/uninstall-task.ps1");
707709
skip_uac_task_uninstaller
708710
.register_template_string("uninstall-task.ps1", xml)

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ fn build_nsis_app_installer(
344344
}
345345

346346
let mut handlebars = Handlebars::new();
347+
handlebars.register_escape_fn(|s| {
348+
let mut output = String::new();
349+
for c in s.chars() {
350+
match c {
351+
'\"' => output.push_str("$\\\""),
352+
'$' => output.push_str("$$"),
353+
'`' => output.push_str("$\\`"),
354+
'\n' => output.push_str("$\\n"),
355+
'\t' => output.push_str("$\\t"),
356+
'\r' => output.push_str("$\\r"),
357+
_ => output.push(c),
358+
}
359+
}
360+
output
361+
});
347362
handlebars
348363
.register_template_string("installer.nsi", include_str!("./templates/installer.nsi"))
349364
.map_err(|e| e.to_string())

tooling/bundler/src/bundle/windows/templates/install-task.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ if ($ChangeDir -ne "") {
2525
# Change directories to the install path
2626
Set-Location -Path $ChangeDir
2727
}
28-
SCHTASKS.EXE /CREATE /XML update.xml /TN "Update {{{product_name}}} - Skip UAC" /F
28+
SCHTASKS.EXE /CREATE /XML update.xml /TN "Update {{product_name}} - Skip UAC" /F

tooling/bundler/src/bundle/windows/templates/installer.nsi

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ Var ReinstallPageCheck
66
!include x64.nsh
77
!include WordFunc.nsh
88

9-
!define MANUFACTURER "{{{manufacturer}}}"
10-
!define PRODUCTNAME "{{{product_name}}}"
11-
!define VERSION "{{{version}}}"
12-
!define INSTALLMODE "{{{install_mode}}}"
13-
!define LICENSE "{{{license}}}"
14-
!define INSTALLERICON "{{{installer_icon}}}"
15-
!define SIDEBARIMAGE "{{{sidebar_image}}}"
16-
!define HEADERIMAGE "{{{header_image}}}"
17-
!define MAINBINARYNAME "{{{main_binary_name}}}"
18-
!define MAINBINARYSRCPATH "{{{main_binary_path}}}"
19-
!define BUNDLEID "{{{bundle_id}}}"
20-
!define OUTFILE "{{{out_file}}}"
21-
!define ARCH "{{{arch}}}"
22-
!define PLUGINSPATH "{{{additional_plugins_path}}}"
23-
!define ALLOWDOWNGRADES "{{{allow_downgrades}}}"
24-
!define DISPLAYLANGUAGESELECTOR "{{{display_language_selector}}}"
25-
!define INSTALLWEBVIEW2MODE "{{{install_webview2_mode}}}"
26-
!define WEBVIEW2INSTALLERARGS "{{{webview2_installer_args}}}"
27-
!define WEBVIEW2BOOTSTRAPPERPATH "{{{webview2_bootstrapper_path}}}"
28-
!define WEBVIEW2INSTALLERPATH "{{{webview2_installer_path}}}"
9+
!define MANUFACTURER "{{manufacturer}}"
10+
!define PRODUCTNAME "{{product_name}}"
11+
!define VERSION "{{version}}"
12+
!define INSTALLMODE "{{install_mode}}"
13+
!define LICENSE "{{license}}"
14+
!define INSTALLERICON "{{installer_icon}}"
15+
!define SIDEBARIMAGE "{{sidebar_image}}"
16+
!define HEADERIMAGE "{{header_image}}"
17+
!define MAINBINARYNAME "{{main_binary_name}}"
18+
!define MAINBINARYSRCPATH "{{main_binary_path}}"
19+
!define BUNDLEID "{{bundle_id}}"
20+
!define OUTFILE "{{out_file}}"
21+
!define ARCH "{{arch}}"
22+
!define PLUGINSPATH "{{additional_plugins_path}}"
23+
!define ALLOWDOWNGRADES "{{allow_downgrades}}"
24+
!define DISPLAYLANGUAGESELECTOR "{{display_language_selector}}"
25+
!define INSTALLWEBVIEW2MODE "{{install_webview2_mode}}"
26+
!define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}"
27+
!define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}"
28+
!define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}"
2929
!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}"
3030
!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
3131

tooling/bundler/src/bundle/windows/templates/main.wxs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
1212
<Product
1313
Id="*"
14-
Name="{{{product_name}}}"
15-
UpgradeCode="{{{upgrade_code}}}"
14+
Name="{{product_name}}"
15+
UpgradeCode="{{upgrade_code}}"
1616
Language="!(loc.TauriLanguage)"
17-
Manufacturer="{{{manufacturer}}}"
18-
Version="{{{version}}}">
17+
Manufacturer="{{manufacturer}}"
18+
Version="{{version}}">
1919

2020
<Package Id="*"
2121
Keywords="Installer"
@@ -42,23 +42,23 @@
4242
<Media Id="1" Cabinet="app.cab" EmbedCab="yes" />
4343

4444
{{#if banner_path}}
45-
<WixVariable Id="WixUIBannerBmp" Value="{{{banner_path}}}" />
45+
<WixVariable Id="WixUIBannerBmp" Value="{{banner_path}}" />
4646
{{/if}}
4747
{{#if dialog_image_path}}
48-
<WixVariable Id="WixUIDialogBmp" Value="{{{dialog_image_path}}}" />
48+
<WixVariable Id="WixUIDialogBmp" Value="{{dialog_image_path}}" />
4949
{{/if}}
5050
{{#if license}}
51-
<WixVariable Id="WixUILicenseRtf" Value="{{{license}}}" />
51+
<WixVariable Id="WixUILicenseRtf" Value="{{license}}" />
5252
{{/if}}
5353

54-
<Icon Id="ProductIcon" SourceFile="{{{icon_path}}}"/>
54+
<Icon Id="ProductIcon" SourceFile="{{icon_path}}"/>
5555
<Property Id="ARPPRODUCTICON" Value="ProductIcon" />
5656
<Property Id="ARPNOREPAIR" Value="yes" Secure="yes" /> <!-- Remove repair -->
5757
<SetProperty Id="ARPNOMODIFY" Value="1" After="InstallValidate" Sequence="execute"/>
5858

5959
<!-- initialize with previous InstallDir -->
6060
<Property Id="INSTALLDIR">
61-
<RegistrySearch Id="PrevInstallDirReg" Root="HKCU" Key="Software\\{{{manufacturer}}}\\{{{product_name}}}" Name="InstallDir" Type="raw"/>
61+
<RegistrySearch Id="PrevInstallDirReg" Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="InstallDir" Type="raw"/>
6262
</Property>
6363

6464
<!-- launch app checkbox -->
@@ -93,27 +93,27 @@
9393
<Directory Id="TARGETDIR" Name="SourceDir">
9494
<Directory Id="DesktopFolder" Name="Desktop">
9595
<Component Id="ApplicationShortcutDesktop" Guid="*">
96-
<Shortcut Id="ApplicationDesktopShortcut" Name="{{{product_name}}}" Description="Runs {{{product_name}}}" Target="[!Path]" WorkingDirectory="INSTALLDIR" />
96+
<Shortcut Id="ApplicationDesktopShortcut" Name="{{product_name}}" Description="Runs {{product_name}}" Target="[!Path]" WorkingDirectory="INSTALLDIR" />
9797
<RemoveFolder Id="DesktopFolder" On="uninstall" />
98-
<RegistryValue Root="HKCU" Key="Software\\{{{manufacturer}}}\\{{{product_name}}}" Name="Desktop Shortcut" Type="integer" Value="1" KeyPath="yes" />
98+
<RegistryValue Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="Desktop Shortcut" Type="integer" Value="1" KeyPath="yes" />
9999
</Component>
100100
</Directory>
101101
<Directory Id="$(var.PlatformProgramFilesFolder)" Name="PFiles">
102-
<Directory Id="INSTALLDIR" Name="{{{product_name}}}"/>
102+
<Directory Id="INSTALLDIR" Name="{{product_name}}"/>
103103
</Directory>
104104
<Directory Id="ProgramMenuFolder">
105-
<Directory Id="ApplicationProgramsFolder" Name="{{{product_name}}}"/>
105+
<Directory Id="ApplicationProgramsFolder" Name="{{product_name}}"/>
106106
</Directory>
107107
</Directory>
108108

109109
<DirectoryRef Id="INSTALLDIR">
110110
<Component Id="RegistryEntries" Guid="*">
111-
<RegistryKey Root="HKCU" Key="Software\\{{{manufacturer}}}\\{{{product_name}}}">
111+
<RegistryKey Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}">
112112
<RegistryValue Name="InstallDir" Type="string" Value="[INSTALLDIR]" KeyPath="yes" />
113113
</RegistryKey>
114114
</Component>
115-
<Component Id="Path" Guid="{{{path_component_guid}}}" Win64="$(var.Win64)">
116-
<File Id="Path" Source="{{{app_exe_source}}}" KeyPath="yes" Checksum="yes"/>
115+
<Component Id="Path" Guid="{{path_component_guid}}" Win64="$(var.Win64)">
116+
<File Id="Path" Source="{{app_exe_source}}" KeyPath="yes" Checksum="yes"/>
117117
</Component>
118118
{{#each binaries as |bin| ~}}
119119
<Component Id="{{ bin.id }}" Guid="{{bin.guid}}" Win64="$(var.Win64)">
@@ -131,20 +131,20 @@
131131
<File Id="UpdateTaskUninstaller" Source="uninstall-task.ps1" KeyPath="yes" Checksum="yes"/>
132132
</Component>
133133
{{/if}}
134-
{{{resources}}}
134+
{{resources}}
135135
<Component Id="CMP_UninstallShortcut" Guid="*">
136136

137137
<Shortcut Id="UninstallShortcut"
138-
Name="Uninstall {{{product_name}}}"
139-
Description="Uninstalls {{{product_name}}}"
138+
Name="Uninstall {{product_name}}"
139+
Description="Uninstalls {{product_name}}"
140140
Target="[System64Folder]msiexec.exe"
141141
Arguments="/x [ProductCode]" />
142142

143143
<RemoveFolder Id="INSTALLDIR"
144144
On="uninstall" />
145145

146146
<RegistryValue Root="HKCU"
147-
Key="Software\\{{{manufacturer}}}\\{{{product_name}}}"
147+
Key="Software\\{{manufacturer}}\\{{product_name}}"
148148
Name="Uninstaller Shortcut"
149149
Type="integer"
150150
Value="1"
@@ -155,15 +155,15 @@
155155
<DirectoryRef Id="ApplicationProgramsFolder">
156156
<Component Id="ApplicationShortcut" Guid="*">
157157
<Shortcut Id="ApplicationStartMenuShortcut"
158-
Name="{{{product_name}}}"
159-
Description="Runs {{{product_name}}}"
158+
Name="{{product_name}}"
159+
Description="Runs {{product_name}}"
160160
Target="[!Path]"
161161
Icon="ProductIcon"
162162
WorkingDirectory="INSTALLDIR">
163-
<ShortcutProperty Key="System.AppUserModel.ID" Value="{{{bundle_id}}}"/>
163+
<ShortcutProperty Key="System.AppUserModel.ID" Value="{{bundle_id}}"/>
164164
</Shortcut>
165165
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
166-
<RegistryValue Root="HKCU" Key="Software\\{{{manufacturer}}}\\{{{product_name}}}" Name="Start Menu Shortcut" Type="integer" Value="1" KeyPath="yes"/>
166+
<RegistryValue Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="Start Menu Shortcut" Type="integer" Value="1" KeyPath="yes"/>
167167
</Component>
168168
</DirectoryRef>
169169

@@ -247,7 +247,7 @@
247247
</Property>
248248

249249
{{#if download_bootstrapper}}
250-
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="INSTALLDIR" Execute="deferred" ExeCommand='powershell.exe -NoProfile -windowstyle hidden try [\{] [\[]Net.ServicePointManager[\]]::SecurityProtocol = [\[]Net.SecurityProtocolType[\]]::Tls12 [\}] catch [\{][\}]; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; Start-Process -FilePath "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" -ArgumentList ({{{webview_installer_args}}} &apos;/install&apos;) -Wait' Return='check'/>
250+
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="INSTALLDIR" Execute="deferred" ExeCommand='powershell.exe -NoProfile -windowstyle hidden try [\{] [\[]Net.ServicePointManager[\]]::SecurityProtocol = [\[]Net.SecurityProtocolType[\]]::Tls12 [\}] catch [\{][\}]; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; Start-Process -FilePath "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" -ArgumentList ({{webview_installer_args}} &apos;/install&apos;) -Wait' Return='check'/>
251251
<InstallExecuteSequence>
252252
<Custom Action='DownloadAndInvokeBootstrapper' Before='InstallFinalize'>
253253
<![CDATA[NOT(REMOVE OR WVRTINSTALLED)]]>
@@ -257,8 +257,8 @@
257257

258258
<!-- Embedded webview bootstrapper mode -->
259259
{{#if webview2_bootstrapper_path}}
260-
<Binary Id="MicrosoftEdgeWebview2Setup.exe" SourceFile="{{{webview2_bootstrapper_path}}}"/>
261-
<CustomAction Id='InvokeBootstrapper' BinaryKey='MicrosoftEdgeWebview2Setup.exe' Execute="deferred" ExeCommand='{{{webview_installer_args}}} /install' Return='check' />
260+
<Binary Id="MicrosoftEdgeWebview2Setup.exe" SourceFile="{{webview2_bootstrapper_path}}"/>
261+
<CustomAction Id='InvokeBootstrapper' BinaryKey='MicrosoftEdgeWebview2Setup.exe' Execute="deferred" ExeCommand='{{webview_installer_args}} /install' Return='check' />
262262
<InstallExecuteSequence>
263263
<Custom Action='InvokeBootstrapper' Before='InstallFinalize'>
264264
<![CDATA[NOT(REMOVE OR WVRTINSTALLED)]]>
@@ -268,8 +268,8 @@
268268

269269
<!-- Embedded offline installer -->
270270
{{#if webview2_installer_path}}
271-
<Binary Id="MicrosoftEdgeWebView2RuntimeInstaller.exe" SourceFile="{{{webview2_installer_path}}}"/>
272-
<CustomAction Id='InvokeStandalone' BinaryKey='MicrosoftEdgeWebView2RuntimeInstaller.exe' Execute="deferred" ExeCommand='{{{webview_installer_args}}} /install' Return='check' />
271+
<Binary Id="MicrosoftEdgeWebView2RuntimeInstaller.exe" SourceFile="{{webview2_installer_path}}"/>
272+
<CustomAction Id='InvokeStandalone' BinaryKey='MicrosoftEdgeWebView2RuntimeInstaller.exe' Execute="deferred" ExeCommand='{{webview_installer_args}} /install' Return='check' />
273273
<InstallExecuteSequence>
274274
<Custom Action='InvokeStandalone' Before='InstallFinalize'>
275275
<![CDATA[NOT(REMOVE OR WVRTINSTALLED)]]>

tooling/bundler/src/bundle/windows/templates/uninstall-task.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ if ((Test-Admin) -eq $false) {
2020
exit
2121
}
2222

23-
SCHTASKS.EXE /DELETE /TN 'Update {{{product_name}}} - Skip UAC' /F
23+
SCHTASKS.EXE /DELETE /TN 'Update {{product_name}} - Skip UAC' /F

tooling/bundler/src/bundle/windows/templates/update-task.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-->
77
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
88
<RegistrationInfo>
9-
<URI>\Update {{{product_name}}} - Skip UAC</URI>
9+
<URI>\Update {{product_name}} - Skip UAC</URI>
1010
</RegistrationInfo>
1111
<Triggers />
1212
<Principals>
@@ -37,7 +37,7 @@
3737
<Actions Context="Author">
3838
<Exec>
3939
<Command>cmd.exe</Command>
40-
<Arguments>/c "%SYSTEMROOT%\System32\msiexec.exe /i %TEMP%\\{{{product_name}}}.msi {{{msiexec_args}}} /promptrestart"</Arguments>
40+
<Arguments>/c "%SYSTEMROOT%\System32\msiexec.exe /i %TEMP%\\{{product_name}}.msi {{msiexec_args}} /promptrestart"</Arguments>
4141
</Exec>
4242
</Actions>
4343
</Task>

0 commit comments

Comments
 (0)