summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Ting <danielzting@gmail.com>2020-07-03 23:00:48 -0500
committerDaniel Ting <danielzting@gmail.com>2020-07-03 23:00:48 -0500
commitb8e6ff9a7fb2eb98e92344d567a1ef085dfb78a4 (patch)
treeb61ab2d27ec1e7f3636d3b6ec749bbfd7689907a
parentb51418842ae684ea201247c6df32092d784e6db0 (diff)
Fix opening URLS with special characters in macOS
The Online Tutorials section of InputMap in the editor's built-in documentation viewer contains this link: docs.godotengine.org/en/latest/tutorials/inputs/inputevent.html#inputmap The macOS implementation for opening a link percent-encodes it before sending it to the browser, resulting in a 404. This is to fix #13422 where filenames with special characters could not be opened in Finder. However, this breaks URLS so I added a check to see if the resource scheme is file:// and if so, only then is it escaped. This allows other schemes like `http`, `ftp`, and `mailto` to be used.
-rw-r--r--platform/osx/os_osx.mm8
1 files changed, 7 insertions, 1 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index dba96ccfcd..4ca89ff4b2 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -272,7 +272,13 @@ String OS_OSX::get_system_dir(SystemDir p_dir) const {
}
Error OS_OSX::shell_open(String p_uri) {
- [[NSWorkspace sharedWorkspace] openURL:[[NSURL alloc] initWithString:[[NSString stringWithUTF8String:p_uri.utf8().get_data()] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]];
+ 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"]) {
+ uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
+ }
+ [[NSWorkspace sharedWorkspace] openURL:uri];
return OK;
}