macOS: Resolve file reference URLs before using them to populate text/uri-list

This commit is contained in:
Kovid Goyal
2026-05-16 16:28:50 +05:30
parent 316e07e8b8
commit ffec9a854a
2 changed files with 9 additions and 2 deletions

View File

@@ -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<NSString *> *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];

View File

@@ -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;