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

[bug] some characters aren't properly escaped in generated XML files on Windows #9030

Closed
bifs opened this issue Feb 29, 2024 · 1 comment
Closed
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@bifs
Copy link
Contributor

bifs commented Feb 29, 2024

Describe the bug

tauri build --verbose gives this error:

Running [tauri_bundler::bundle::windows::msi::wix] candle for "main.wxs"
     Running [tauri_bundler::bundle::common] Command `C:\Users\me\AppData\Local\tauri/WixTools\candle.exe  -arch x64 main.wxs -dSourceDir=D:\docs\repos\my-app\src-tauri\target\release\my-app.exe`
Windows Installer XML Toolset Compiler version 3.11.2.4516
Copyright (c) .NET Foundation and contributors. All rights reserved.

main.wxs
D:\docs\repos\my-app\src-tauri\target\release\wix\x64\main.wxs(103) : error CNDL0104 : Not a valid source file; detail: An error occurred while parsing EntityName. Line 103, position 690211.
       Error [tauri_cli_node] failed to bundle project: error running candle.exe

where Line 103, position 690211 points to an & character, which should be escaped as & for the XML to be valid.

// main.wxs, around 103:690211
<Component Id="I5da52d87de654b5885e857b2d70119f8" Guid="9767c26b-f332-4078-9a8e-c02c11a73330" Win64="$(var.Win64)" KeyPath="yes"><File Id="PathFile_I5da52d87de654b5885e857b2d70119f8" Source="D:\docs\repos\my-app\src-tauri\bin\blend-utils\_internal\bpy\4.0\scripts\presets\camera\Blackmagic_Pocket_&_Studio.py" /></Component>

The & character was introduced from here:

files.push_str(
format!(
r#"<Component Id="{id}" Guid="{guid}" Win64="$(var.Win64)" KeyPath="yes"><File Id="PathFile_{id}" Source="{path}" /></Component>"#,
id = file.id,
guid = file.guid,
path = file.path.display()
).as_str()
);

and rendered by handlebars:
let main_wxs_path = output_path.join("main.wxs");
write(main_wxs_path, handlebars.render("main.wxs", &data)?)?;

Reproduction

on Windows,

  1. create tauri-app -y
  2. cd tauri-app
  3. touch "src-tauri/&ice.cream" and bundle it as a resource
{
  "tauri": {
    "bundle": {
      "identifier": "com.tauri.dev1",
      "resources": [
        "&ice.cream"
      ],
      // ...
    }
    // ...
  }
  // ...
}
  1. pnpm i
  2. pnpm tauri build --verbose

then it would print the error above.

Expected behavior

The bundling process should be successful.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 122.0.2365.52
    ✔ MSVC:
        - Visual Studio Build Tools 2017
        - Visual Studio Build Tools 2022
        - Visual Studio Community 2022
    ✔ rustc: 1.74.1 (a28077b28 2023-12-04)
    ✔ cargo: 1.74.1 (ecb9851af 2023-10-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.5.1
    - pnpm: 8.6.7
    - npm: 9.8.0

[-] Packages
    - tauri [RUST]: 1.6.1
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.7
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.10

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: SolidJS
    - bundler: Vite

Stack trace

No response

Additional context

I've found the default escaping behavior is disabled intentionally (possibly to render XML elements from a raw string):

handlebars.register_escape_fn(handlebars::no_escape);

and I can solve this issue by applying the default behavior to the problematic strings.
https://github.com/sunng87/handlebars-rust/blob/3b69fb320230374b39a5c7401c5bed817b133696/src/registry.rs#L41-L51
https://github.com/sunng87/handlebars-rust/blob/3b69fb320230374b39a5c7401c5bed817b133696/src/support.rs#L42-L58

- use handlebars::{to_json, Handlebars};
+ use handlebars::{html_escape, to_json, Handlebars};
// ..
      files.push_str(
        format!(
          r#"<Component Id="{id}" Guid="{guid}" Win64="$(var.Win64)" KeyPath="yes"><File Id="PathFile_{id}" Source="{path}" /></Component>"#,
          id = file.id,
          guid = file.guid,
-          path = file.path.display()
+          path = html_escape(&file.path.display().to_string())
        ).as_str()
      );
// ..
      format!(
        r#"<Directory Id="I{id}" Name="{name}">{files}{directories}</Directory>"#,
        id = Uuid::new_v4().as_simple(),
-        name = self.name,
+        name = html_escape(&self.name),
        files = files,
        directories = directories,
      )

I've tested this works by building cli.win32-x64-msvc.node and putting it in node_modules/@tauri-apps/cli.

I couldn't open a PR because I'm not sure this is a right way/style to fix it.
I'd appreciate any kind of comments. Thanks in advance.

@bifs bifs added status: needs triage This issue needs to triage, applied to new issues type: bug labels Feb 29, 2024
@bifs bifs changed the title [bug] some characters aren't properly escaped in XML [bug] some characters aren't properly escaped in generated XML files on Windows Feb 29, 2024
bifs pushed a commit to bifs/tauri that referenced this issue Feb 29, 2024
…-apps#9030)

- replace characters invalid in XML with their escaped form to properly bundle resources with such characters in their pathnames.

fxup
bifs pushed a commit to bifs/tauri that referenced this issue Feb 29, 2024
…-apps#9030)

- replace characters invalid in XML with their escaped form to properly bundle resources with such characters in their pathnames.
@amrbashir
Copy link
Member

@bifs thank you for tracking this down. Applying the default html escape on the path only should be fine, feel free to open a PR

bifs added a commit to bifs/tauri that referenced this issue Mar 1, 2024
…-apps#9030)

- replace characters invalid in XML with their escaped form to properly bundle resources with such characters in their pathnames.
amrbashir pushed a commit that referenced this issue Mar 4, 2024
* fix(bundler): escape potentially problematic strings in an XML (#9030)

- replace characters invalid in XML with their escaped form to properly bundle resources with such characters in their pathnames.

* change file
amrbashir added a commit that referenced this issue Apr 18, 2024
* chore: port PR template from `dev` branch (#9004)

* fix(runtime-wry): avoid panic during clipboard initialization on wayland (#9003)

closes #8964

* ci: downgrade thread_local to 1.1.7 in msrv list (#9012)

* Apply Version Updates From Current Changes (v1) (#9013)

Co-authored-by: lucasfernog <[email protected]>

* fix(bundler): escape potentially problematic strings in an XML (#9040)

* fix(bundler): escape potentially problematic strings in an XML (#9030)

- replace characters invalid in XML with their escaped form to properly bundle resources with such characters in their pathnames.

* change file

* fix(cli): use `matched_path_or_any_parents` when checking if a file is ignored (#8903)

* fix: taurignore ignoreing folders not working for watch

* docs: add to changes

* fix: panic: path is expected to be under the root

* Update taurignore-ignoring-folders-not-working-for-watch.md

* Update taurignore-ignoring-folders-not-working-for-watch.md

* fix(cli): migrate to stable features of `log` crate (#9119)

* fix(cli): migrate to stable features of `log` crate

* to_cow_str

* Apply Version Updates From Current Changes (v1) (#9074)

Co-authored-by: lucasfernog <[email protected]>

* fix(core/path): remove suffix in basename only once (#9166)

* fix(core/path): remove suffix in basename only once

ref: #9064

* Update tooling/api/src/path.ts

---------

Co-authored-by: Lucas Fernandes Nogueira <[email protected]>

* fix(cli): Clone Options struct after mutating it. (#9188)

* fix(bundler): Fix nsis resource paths on non-windows build systems. (#9281)

* fix(bundler): Fix nsis resource paths on non-windows build systems.

* remove leftover from alternative

* fix(bundler/nsis): Don't use /R flag on installation dir (#9282)

* fix(cli): upgrade heck to better support Chinese/Japanese prodcut name on Linux (#9298)

* chore: fix clippy false positive (#9329)

* fix(cli/info): fix crash when checking node version (#9411)

closes #9396

---------

Co-authored-by: Amr Bashir <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: lucasfernog <[email protected]>
Co-authored-by: bifs <[email protected]>
Co-authored-by: anatawa12 <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Jet Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants