fix(opener): strip UNC prefix before passing path to ILCreateFromPathW on Windows#3335
fix(opener): strip UNC prefix before passing path to ILCreateFromPathW on Windows#3335arelove wants to merge 3 commits intotauri-apps:v2from
Conversation
Package Changes Through c17b0aaThere 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 VersionsThe following package releases are the planned based on the context of changes in this pull request.
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))); |
There was a problem hiding this comment.
Genuine question, is it safe to always convert \\?\UNC\ to \\?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Sounds reasonable, we could go with either this or use absolute instead of canonicalize (#3343)
Fixes #3304
dunce::canonicalizeconverts UNC paths like\\server\share\file.mkvto
\\?\UNC\server\share\file.mkvon Windows. The\\?\prefix wasalready being stripped for local paths, but not for UNC — so
ILCreateFromPathWwas receiving an unsupported prefix and returning NULL.Fix
Added
normalize_path_for_shell()in the Windowsimpmodule to strip\\?\UNC\and replace it with\\before passing toILCreateFromPathW.Tests
Running unittests src\lib.rs (target\debug\deps\tauri_plugin_opener-88af2df7c99491c7.exe)
running 4 tests
Note: the 4 failing doc-tests are pre-existing and unrelated to this change.``