Skip to content

Commit

Permalink
Merge pull request #88126 from bruvzg/mac_open_shell
Browse files Browse the repository at this point in the history
[macOS] Allow `open_shell` to handle filenames without `file://`.
  • Loading branch information
akien-mga committed Feb 9, 2024
2 parents 4966b22 + cc313a1 commit d351299
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion platform/macos/os_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,11 @@
Error OS_MacOS::shell_open(String p_uri) {
NSString *string = [NSString stringWithUTF8String:p_uri.utf8().get_data()];
NSURL *uri = [[NSURL alloc] initWithString:string];
// Escape special characters in filenames
if (!uri || !uri.scheme || [uri.scheme isEqual:@"file"]) {
// No scheme set, assume "file://" and escape special characters.
if (!p_uri.begins_with("file://")) {
string = [NSString stringWithUTF8String:("file://" + p_uri).utf8().get_data()];
}
uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
}
[[NSWorkspace sharedWorkspace] openURL:uri];
Expand Down

0 comments on commit d351299

Please sign in to comment.