mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
macOS: Resolve file reference URLs before using them to populate text/uri-list
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user