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] Using Chinese characters in the options parameter of the invoke method causes the type returned by request.body() to be not Raw. #10821

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

Comments

@SRutile
Copy link

SRutile commented Aug 29, 2024

Describe the bug

I encountered an issue when using the writeFile method. If Chinese characters are present in the options parameter of the invoke method, it causes the type returned by request.body() to be not Raw.

Reproduction

#[tauri::command]
async fn test(
    request: tauri::ipc::Request<'_>,
) -> Result<(), String> {
    println!("{:?}", request.body());
    println!("{:?}", request.headers().get("path"));

    if let tauri::ipc::InvokeBody::Raw(data) = request.body() {
        println!("{:?}", data);
    } else {
        println!("failed");
    }
    
    Ok(())
}
const data = new TextEncoder().encode("H");
invoke("test", data, {
    headers: {
        path: "a测试"
    }
})
Json(Array [Number(72)])
Some("aa\xe6\xb5\x8b\xe8\xaf\x95")
failed

Expected behavior

Make request.body() return the type as Raw.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.19044 X64
    ✔ WebView2: 128.0.2739.42
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.82.0-nightly (100fde524 2024-08-28)
    ✔ cargo: 1.82.0-nightly (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: nightly-x86_64-pc-windows-msvc (default)
    - node: 20.15.0
    - pnpm: 9.4.0
    - npm: 10.8.1
    - bun: 1.1.17

[-] Packages
    - tauri [RUST]: 2.0.0-rc.7
    - tauri-build [RUST]: 2.0.0-rc.7
    - wry [RUST]: 0.42.0
    - tao [RUST]: 0.29.1
    - tauri-cli [RUST]: 2.0.0-rc.5
    - @tauri-apps/api [NPM]: 2.0.0-rc.3
    - @tauri-apps/cli [NPM]: 2.0.0-rc.7

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

@SRutile SRutile added status: needs triage This issue needs to triage, applied to new issues type: bug labels Aug 29, 2024
@amrbashir
Copy link
Member

This is just how headers work, only ISO-8859-1 strings is accepted as valid header. To workaround this, you can use encodeURIComponent and then use percent_encoding crate on Rust side to decode the value.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
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