Skip to content

Commit

Permalink
fix: Ensure file paths derived from pasteboard operations are properl…
Browse files Browse the repository at this point in the history
…y escaped
  • Loading branch information
AlexJuca committed Jan 13, 2025
1 parent 5081e65 commit ac45070
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions macos/Sources/Helpers/NSPasteboard+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ extension NSPasteboard {

/// Gets the contents of the pasteboard as a string following a specific set of semantics.
/// 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 esures file path is properly escaped.
/// - Tries to get any string from the pasteboard.
/// If all of the above fail, returns None.
func getOpinionatedStringContents() -> String? {
if let urls = readObjects(forClasses: [NSURL.self]) as? [URL],
urls.count > 0 {
return urls
.map { $0.isFileURL ? $0.path : $0.absoluteString }
.map { $0.isFileURL ? Ghostty.Shell.escape($0.path) : $0.absoluteString }
.joined(separator: " ")
}

Expand Down

0 comments on commit ac45070

Please sign in to comment.