From ffec9a854a9d2aff6e970ef62376109b5099e5dd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 May 2026 16:28:50 +0530 Subject: [PATCH] macOS: Resolve file reference URLs before using them to populate text/uri-list --- glfw/cocoa_window.m | 10 ++++++++-- kitty/dnd.c | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 81332d34f..69856262d 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1669,13 +1669,19 @@ send_data_available_event_on_next_event_loop_tick(GLFWid wid, const char *mime) static void create_uri_list(_GLFWDropData *d, NSArray *urls) { NSMutableArray *items = [NSMutableArray array]; - NSCharacterSet *allowedChars = [NSCharacterSet URLQueryAllowedCharacterSet]; + NSCharacterSet *c1 = [NSCharacterSet URLQueryAllowedCharacterSet]; + NSCharacterSet *c2 = [NSCharacterSet URLPathAllowedCharacterSet]; for (NSURL *url in urls) { + NSCharacterSet *allowedChars = c1; + if ([url isFileURL]) { + url = [url filePathURL]; + allowedChars = c2; + } NSString *absoluteString = url.absoluteString; NSString *q = [absoluteString stringByAddingPercentEncodingWithAllowedCharacters:allowedChars]; [items addObject:q]; } - NSString *result = [urls componentsJoinedByString:@"\r\n"]; + NSString *result = [items componentsJoinedByString:@"\r\n"]; NSData *data = [result dataUsingEncoding:NSUTF8StringEncoding]; NSInputStream *inputStream = [NSInputStream inputStreamWithData:data]; [inputStream open]; diff --git a/kitty/dnd.c b/kitty/dnd.c index 45dd4f572..f07851bed 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -1043,6 +1043,7 @@ do_drop_request_uri_data(Window *w, int32_t mime_idx, int32_t file_idx) { struct stat st; if (lstat(path, &st) < 0) { + log_error("lstat() of uri-list entry num: %d (%s) failed with error: %s", file_n, path, strerror(errno)); switch (errno) { case ENOENT: case ENOTDIR: drop_send_error(w, ENOENT, "drop data file does not exist"); break; case EACCES: case EPERM: drop_send_error(w, EPERM, "permission denied for stat() on drop data file"); break;