Skip to content

URL in WindowManager.prepare_window() has double slashes #2281

@woubuc

Description

@woubuc

Describe the bug

When a page URL is joined with the base URL, too many slashes are added, causing some dev servers (in my case, the Nuxt dev server) to return a 404 instead of showing the page.

With config..

"devPath": "http://localhost:3000",

..WindowManager.get_url() returns http://localhost:3000/ with a trailing slash, even though in the config file it doesn't have a trailing slash.

However, WindowManager.prepare_window() combines the base url with the path like this..

format!("{}/{}", url, path.to_string_lossy())

..which means that this code..

app.create_window(
    "login".into(),
    WindowUrl::App("login".into()),
    |builder, attrs| { [...] },
).unwrap();

..results in the webview trying to load http://localhost:3000//login because the format call adds an additional slash inbetween the base url and the path. This is a problem if the dev server doesn't normalise the path and just tries to match //login - resulting in a 404 instead of the expected page.

If I replace that format line in manager.rs in the Tauri project with the following, to prevent adding a slash inbetween the parts if the base url already has a trailing slash..

let separator = match url.ends_with("/") {
    true => "",
    false => "/",
};

format!("{}{}{}", url, separator, path.to_string_lossy())

..then I get http://localhost:3000/login and everything works as expected.

I don't know what platform and compatibility considerations the URLs in Tauri have, so I don't know if this fix would be applicable for all users and build targets. But if the above fix is acceptable I'll gladly create a pull request.

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 91.0.864.71

Node.js environment
  Node.js - 14.16.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 6.14.11
  yarn - 1.22.4

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/.idea
/.nuxt
/assets
/components
/dist
/i18n
/layouts
/node_modules
/pages
/plugins
/src-tauri
/static
/types
/utils

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-
eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://localhost:3000
  framework - Vue.js (Nuxt)
  bundler - Webpack

Metadata

Metadata

Assignees

No one assigned

    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