Skip to content

fix(opener): strip UNC prefix before passing path to ILCreateFromPathW on Windows#3335

Closed
arelove wants to merge 3 commits intotauri-apps:v2from
arelove:fix/opener-unc-path-reveal
Closed

fix(opener): strip UNC prefix before passing path to ILCreateFromPathW on Windows#3335
arelove wants to merge 3 commits intotauri-apps:v2from
arelove:fix/opener-unc-path-reveal

Conversation

@arelove
Copy link
Copy Markdown

@arelove arelove commented Mar 8, 2026

Fixes #3304

dunce::canonicalize converts UNC paths like \\server\share\file.mkv
to \\?\UNC\server\share\file.mkv on Windows. The \\?\ prefix was
already being stripped for local paths, but not for UNC — so
ILCreateFromPathW was receiving an unsupported prefix and returning NULL.

Fix

Added normalize_path_for_shell() in the Windows imp module to strip
\\?\UNC\ and replace it with \\ before passing to ILCreateFromPathW.

Tests

Running unittests src\lib.rs (target\debug\deps\tauri_plugin_opener-88af2df7c99491c7.exe)

running 4 tests

test reveal_item_in_dir::tests::local_path_unchanged ... ok
test reveal_item_in_dir::tests::plain_unc_unchanged ... ok
test reveal_item_in_dir::tests::unc_path_converts_correctly ... ok
test reveal_item_in_dir::tests::unc_path_should_not_have_extended_prefix ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Note: the 4 failing doc-tests are pre-existing and unrelated to this change.``

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

Package Changes Through c17b0aa

There are 14 changes which include sql with minor, sql-js with minor, fs with minor, fs-js with minor, http with patch, http-js with patch, updater with patch, updater-js with patch, nfc with patch, nfc-js with patch, dialog with minor, dialog-js with minor, deep-link with patch, deep-link-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.41 2.0.42
api-example-js 2.0.37 2.0.38
deep-link-example-js 2.2.10 2.2.11
deep-link 2.4.7 2.4.8
deep-link-js 2.4.7 2.4.8
fs 2.4.5 2.5.0
fs-js 2.4.5 2.5.0
dialog 2.6.0 2.7.0
dialog-js 2.6.0 2.7.0
http 2.5.7 2.5.8
http-js 2.5.7 2.5.8
nfc 2.3.4 2.3.5
nfc-js 2.3.4 2.3.5
persisted-scope 2.3.5 2.3.6
single-instance 2.4.0 2.4.1
sql 2.3.2 2.4.0
sql-js 2.3.2 2.4.0
updater 2.10.0 2.10.1
updater-js 2.10.0 2.10.1

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

pub(super) fn normalize_path_for_shell(path: &Path) -> std::borrow::Cow<'_, Path> {
if let Some(s) = path.to_str() {
if let Some(unc) = s.strip_prefix(r"\\?\UNC\") {
return std::borrow::Cow::Owned(PathBuf::from(format!(r"\\{}", unc)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genuine question, is it safe to always convert \\?\UNC\ to \\?

Copy link
Copy Markdown
Author

@arelove arelove Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's safe specifically for ILCreateFromPathW since that Shell API doesn't support the \?\ prefix at all. The one edge case worth noting: if the UNC path exceeds MAX_PATH (260 chars), stripping \?\UNC\ could cause issues in other parts of the code that rely on extended-length path support. For the typical use case of revealing a file in Explorer this should be fine though.
But maybe I missed something, I'm not sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, we could go with either this or use absolute instead of canonicalize (#3343)

This comment was marked as resolved.

@arelove arelove closed this Mar 12, 2026
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.

tauri-plugin-opener bug - revealItemInDir fails for UNC network paths on Windows

3 participants