Skip to content

fix(tauri): Strip Windows UNC prefix from canonicalized paths #17

@wilcorrea

Description

@wilcorrea

Summary

CodeRabbit identified a Windows-specific issue in PR #16: std::fs::canonicalize on Windows produces extended-length UNC paths with \\?\ prefix, which are incompatible with many applications including Node.js.

Problem

In ipc_common.rs:25-27, the code uses:

Ok(abs_path) => {
    let path_str = abs_path.to_string_lossy().to_string();

On Windows, canonicalize converts paths like C:\Users\... to \\?\C:\Users\.... The frontend "open-file" event handler (which uses Node.js/JavaScript) will receive this broken path string, causing failures on Windows - the primary platform this fix was meant to support.

Solution Options

Option 1: Manual prefix strip (no dependencies)

Ok(abs_path) => {
    // Strip Windows extended-length prefix so the frontend
    // receives a plain path like C:\... instead of \\?\C:\...
    let path_str = abs_path.to_string_lossy()
        .strip_prefix(r"\\?\")
        .map(str::to_string)
        .unwrap_or_else(|| abs_path.to_string_lossy().to_string());

Option 2: Use dunce crate (recommended)

Add to Cargo.toml:

dunce = "1"

Replace std::fs::canonicalize with dunce::canonicalize:

match dunce::canonicalize(&path) {
    Ok(abs_path) => {
        let path_str = abs_path.to_string_lossy().to_string();

The dunce crate is widely used as a wrapper over std::fs::canonicalize that automatically strips the \\?\ prefix on Windows.

References

Files Affected

  • apps/tauri/src-tauri/src/ipc_common.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions