macOS: Unescape dragged path when NSURL doesn't (#5059)

This commit is contained in:
Abe Jellinek 2025-02-25 05:28:12 -05:00 • committed by GitHub
parent c049120efb
commit 90a9c5164a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2097,6 +2097,16 @@ Zotero.DragDrop = {
continue;
}
file.QueryInterface(Components.interfaces.nsIFile);
if (Zotero.isMac && /%[0-9A-F]{2}/.test(file.path) && !file.exists()) {
// On macOS, Firefox reads a file URL from `public.file-url`,
// constructs an NSURL from it, then gets its unescaped path using
// stringByReplacingPercentEscapesUsingEncoding:
// https://searchfox.org/mozilla-central/rev/fcfb558f/widget/cocoa/nsCocoaUtils.mm#1668-1673
// But that function uses a strict URI parser that chokes on things
// like errant brackets in the file path, and when it chokes, the
// URI is left escaped. Unescape it ourselves.
file = Zotero.File.pathToFile(decodeURIComponent(file.path));
}
// Don't allow folder drag
if (file.isDirectory()) {
continue;