Fix NSURL misdetection routing SSH commands to openURL - #302
Conversation
Only treat command strings as URLs when they have an explicit http/https scheme, since NSURL's parser has become more lenient over time and was misrouting SSH commands to NSWorkspace openURL. Also logs AppleScript execution errors instead of discarding them. Bumps minimum deployment target from 10.9 to 10.13.
|
Hit the same bug independently and landed on a slightly different rule, sharing in case it's useful. Restricting to An alternative that keeps them working: treat an entry as a URL only when it has a scheme and contains no whitespace. - (NSURL *) urlForEntry: (NSString *) entry
{
if ([entry rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location != NSNotFound)
return nil;
NSURL *url = [NSURL URLWithString:entry];
return url.scheme.length ? url : nil;
}The whitespace test is what does the work. Every realistic command contains a space, and the ones that legitimately contain a colon ( Root cause, for anyone who finds this by searching the error message: Separately, +1 on logging the AppleScript execution errors. That's a real improvement I didn't have. I have a fork at https://github.com/morri5/shuttle carrying this plus a universal arm64 build and a |
Restricting to http/https broke vnc:// and ssh:// entries, which legitimately need to go through -openURL: to reach Screen Sharing and the registered SSH handler. A URL never contains unescaped whitespace, so checking for that instead (plus requiring a non-empty scheme) correctly distinguishes shell commands from real URLs regardless of which schemes exist. Root cause credit and this fix approach: github.com/morri5, via PR comment.
|
Pushed an update using your whitespace + scheme approach, tested against both a plain command and the new-window/new-tab paths. Thanks for the fix and the root-cause detail. Credited you in the PR commit message. |
Only treat command strings as URLs when they have an explicit http/https scheme, since NSURL's parser has become more lenient over time and was misrouting SSH commands to NSWorkspace openURL. Also logs AppleScript execution errors instead of discarding them. Bumps minimum deployment target from 10.9 to 10.13.