Skip to content

pasteboard: ignore non-file URLs in macOS files() - #560

Merged
boyan01 merged 1 commit into
mainfrom
pasteboard-macos-file-urls-only
Nov 16, 2026
Merged

boyan01 merged 1 commit into
mainfrom
pasteboard-macos-file-urls-only

Conversation

@boyan01

@boyan01 boyan01 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #512.

Previously, PasteboardPlugin.files() on macOS called NSPasteboard.general.readObjects(forClasses: [NSURL.self], options: nil) and collected (url as? NSURL)?.path without checking isFileURL, causing copied web URLs (e.g. https://example.com/etc/hosts) to be returned as local file paths (/etc/hosts).

 packages/pasteboard/macos/pasteboard/Sources/pasteboard/PasteboardPlugin.swift
   func files(result: FlutterResult, pasteboard: NSPasteboard = .general)
-    pasteboard.readObjects(forClasses: [NSURL.self], options: nil)
+    pasteboard.readObjects(forClasses: [NSURL.self], options: [.urlReadingFileURLsOnly: true])
-    if let path = (url as? NSURL)?.path
+    if let url = url as? NSURL, url.isFileURL, let path = url.path

Evidence

  • Before: flutter test test/macos_files_test.dart reproduced the bug against NSPasteboard.withUniqueName(), returning ["/etc/hosts", "/tmp/file.txt", "/etc/passwd"] instead of [].
  • After:
    • flutter test in packages/pasteboard → +1: All tests passed! (verifies web URLs excluded, local file paths with spaces/CJK/special characters preserved, mixed URLs filtered in order, and empty pasteboard).
    • flutter analyze in packages/pasteboard → No issues found!

Merge Danger

Door: two-way

Blast Radius: minimal

Scoped to packages/pasteboard macOS files() and a macOS-only unit test (test/macos_files_test.dart, skipped on other platforms).

@boyan01
boyan01 merged commit bde07ed into main Nov 16, 2026
7 checks passed
@boyan01
boyan01 deleted the pasteboard-macos-file-urls-only branch November 16, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pasteboard] macOS files() treats copied web URLs as file paths

1 participant