macOS: check the resource the URL refers to.

Fixes #12727. [`NSURL.hasDirectoryPath` doesn't do this](https://developer.apple.com/documentation/foundation/nsurl/hasdirectorypath).

We don't need to check this in NewTerminalIntent since AppIntent already appends `/` to the directory.
This commit is contained in:
Lukas
2026-05-18 20:40:57 +02:00
parent 4b7bf0b20e
commit fdf84ef7ce

View File

@@ -42,7 +42,13 @@ class ServiceProvider: NSObject {
// to their directories because that's the only thing we can open.
let directoryURLs = Set(
pathURLs.map { url -> URL in
url.hasDirectoryPath ? url : url.deletingLastPathComponent()
/// We check file system resources here because
/// NSURL doesn't append `/` when reading string contents from pasteboard
/// ```
/// NSURL(pasteboardPropertyList: "/System/Library".propertyList(), ofType: .fileURL)?.hasDirectoryPath
/// ```
let isDirectory = (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? url.hasDirectoryPath
return isDirectory ? url : url.deletingLastPathComponent()
}
)