Skip to content

[v3, Windows] Calling Dialogs.OpenFile() from JS runtime returns unescaped backslashes in the filepath #4139

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

Closed
zikaiqin opened this issue Mar 16, 2025 · 2 comments
Labels
Bug Something isn't working

Comments

@zikaiqin
Copy link

Description

When calling Dialogs.OpenFile() from JS and selecting a file, the returned string isn't evaluated properly because of unescaped backslahes

To Reproduce

  1. Open the open file dialog from the frontend:
import {Dialogs} from "@wailsio/runtime";

Dialogs.OpenFile().then((result) => {
  console.log(result);
});
  1. Select a file:

Image

  1. Single backslashes in JS are used to escape characters, so the string isn't evaluated properly:

Image

Expected behaviour

Calling Dialogs.OpenFile() from JS should return a usable filepath (e.g. "D:\\notes\\time.txt")

Screenshots

No response

Attempted Fixes

Workaround for v3

Call application.OpenFileDialog().PromptForSingleSelection() from Go, as instructed in the docs

System Details

# System 

┌──────────────────────────────────────────────────────────────────────────────┐
| Name              | Windows 10 Home                                          |
| Version           | 2009 (Build: 19045)                                      |
| ID                | 22H2                                                     |
| Branding          | Windows 10 Home                                          |
| Platform          | windows                                                  |
| Architecture      | amd64                                                    |
| Go WebView2Loader | true                                                     |
| WebView2 Version  | 133.0.3065.92                                            |
| CPU               | Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz                  |
| GPU 1             | NVIDIA GeForce GTX 1080 (NVIDIA) - Driver: 32.0.15.7247  |
| Memory            | 32GB                                                     |
└──────────────────────────────────────────────────────────────────────────────┘

# Build Environment 

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI      | v3.0.0-alpha.9                                                                                                            |
| Go Version     | go1.23.4                                                                                                                  |
| -buildmode     | exe                                                                                                                       |
| -compiler      | gc                                                                                                                        |
| CGO_CFLAGS     |                                                                                                                           |
| CGO_CPPFLAGS   |                                                                                                                           |
| CGO_CXXFLAGS   |                                                                                                                           |
| CGO_ENABLED    | 1                                                                                                                         |
| CGO_LDFLAGS    |                                                                                                                           |
| DefaultGODEBUG | asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1 |
| GOAMD64        | v1                                                                                                                        |
| GOARCH         | amd64                                                                                                                     |
| GOOS           | windows                                                                                                                   |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies 

┌───────────────────────────┐
| NSIS | Not Installed      |
| npm  | 11.0.0             |
└─ * - Optional Dependency ─┘

# Diagnosis 

 SUCCESS  Your system is ready for Wails development!

Additional context

Related threads

Thread on discord discussing the issue: Windows Path and JS auto escaping

package.json

{
  "name": "frontend",
  "version": "0.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "frontend",
      "version": "0.0.0",
      "devDependencies": {
        "@wailsio/runtime": "latest",
        "vite": "^5.0.0"
      }
    },
    ...
    "node_modules/@wailsio/runtime": {
      "version": "3.0.0-alpha.66",
      "resolved": "https://registry.npmjs.org/@wailsio/runtime/-/runtime-3.0.0-alpha.66.tgz",
      "integrity": "sha512-ENLu8rn1griL1gFHJqkq1i+BVxrrA0JPJHYneUJYuf/s54kjuQViW0RKDEe/WTDo56ABpfykrd/T8OYpPUyXUw==",
      "dev": true,
      "license": "MIT"
    },
    ...
  }
}
@zikaiqin zikaiqin added the Bug Something isn't working label Mar 16, 2025
@fbbdev
Copy link
Collaborator

fbbdev commented Mar 16, 2025

Hello and thanks for reporting this!

I will investigate the issue, but please note that the package published on npm is only compatible with the development version of wails v3 (tip of the v3-alpha branch), not with the tagged release alpha.9.

Indeed, the encoding of dialog responses has changed recently, and that might be the cause of the malfunction you're observing.

@leaanthony
Copy link
Member

I believe this is now fixed by #4188. Please reopen if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants