Skip to content

fix(core): return . from path.dirname for a bare file name - #16725

Open
burrows99 wants to merge 1 commit into
tauri-apps:devfrom
burrows99:fix/path-dirname-bare-name
Open

burrows99 wants to merge 1 commit into
tauri-apps:devfrom
burrows99:fix/path-dirname-bare-name

Conversation

@burrows99

Copy link
Copy Markdown

path.dirname from @tauri-apps/api/path returns an empty string for a path with no directory part, while Node returns .:

call before after (Node.js)
dirname('file.txt') "" "."
dirname('README.md') "" "."
dirname('notes/') "" "."

Path::parent returns Some("") for a bare file name, and the command passed it through. It now returns . in that case. Everything else is unchanged, including dirname('/'), which still rejects with "path does not have a parent".

flowchart TD
    A[dirname with a bare file name] --> B{Path::parent}
    B -->|Before| C[empty string returned]
    B -->|After| D[dot returned like Node.js]
Loading

Narrated recording of a Tauri app calling the JS API, before (dev) then after (this branch), then the unchanged calls (sound on):

evidence.mp4

The app is examples/resources (it already grants core:path:default) with its page temporarily replaced by one that prints await dirname(...) results; that page is not part of this PR.

Unchanged behaviour checked

In the running app (both builds): dirname('/path/to/somedir/') -> "/path/to", dirname('src/main.rs') -> "src", dirname('./a') -> ".", dirname('/a') -> "/", dirname('/') -> rejects.

Tests

  • New dirname unit test in crates/tauri/src/path/plugin.rs. With dev's function it fails (left: "", right: "."); with this change cargo test -p tauri --lib path::plugin passes (4 tests).
  • cargo clippy -p tauri --lib --tests: no warnings in the changed file. rustfmt --check clean.
  • Run on macOS only; not run on Windows.

Change file: .changes/path-dirname-bare-name.md (tauri: patch:bug).

This PR was written with AI assistance (Claude Code), including the test and this description; the change and its results were checked as listed above.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant