fix: Ensure file paths derived from pasteboard operations are properly escaped

This commit is contained in:
Alexandre Antonio Juca
2025-01-14 00:01:37 +01:00
parent 5081e65570
commit 39bb949973

View File

@ -9,14 +9,14 @@ extension NSPasteboard {
/// Gets the contents of the pasteboard as a string following a specific set of semantics. /// Gets the contents of the pasteboard as a string following a specific set of semantics.
/// Does these things in order: /// Does these things in order:
/// - Tries to get the absolute filesystem path of the file in the pasteboard if there is one. /// - Tries to get the absolute filesystem path of the file in the pasteboard if there is one and ensures the file path is properly escaped.
/// - Tries to get any string from the pasteboard. /// - Tries to get any string from the pasteboard.
/// If all of the above fail, returns None. /// If all of the above fail, returns None.
func getOpinionatedStringContents() -> String? { func getOpinionatedStringContents() -> String? {
if let urls = readObjects(forClasses: [NSURL.self]) as? [URL], if let urls = readObjects(forClasses: [NSURL.self]) as? [URL],
urls.count > 0 { urls.count > 0 {
return urls return urls
.map { $0.isFileURL ? $0.path : $0.absoluteString } .map { $0.isFileURL ? Ghostty.Shell.escape($0.path) : $0.absoluteString }
.joined(separator: " ") .joined(separator: " ")
} }