Ignore shared URLs in file processor#3037
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents the shared-file processor from attempting to read HTTP(S) deep links as local files, avoiding PathNotFoundException noise when a URL is shared/opened and ReceiveSharingIntent delivers it as a “file”.
Changes:
- Add an early-return in
_processSharedFileswhen the shared path is anhttp://orhttps://URL. - Emit a diagnostic log when a shared URL is ignored.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (filePath.startsWith('https://') || filePath.startsWith('http://')) { | ||
| debugPrint('Ignored shared URL in file processor: $filePath'); | ||
| return; |
There was a problem hiding this comment.
debugPrint logs the full shared URL ($filePath). Shared URLs can include private paths or query parameters, so avoid printing the full value in logs (especially in release). Consider guarding this log with kDebugMode, or logging only the scheme/host (or a redacted version).
| Future<void> _processSharedFiles(List<SharedMediaFile> files) async { | ||
| if (files.isEmpty) return; | ||
| final filePath = files.first.path; | ||
| if (filePath.startsWith('https://') || filePath.startsWith('http://')) { |
There was a problem hiding this comment.
The URL detection uses startsWith('https://') || startsWith('http://'), which is a brittle string check (e.g., it can miss valid URLs with different casing or leading whitespace). Using Uri.tryParse(filePath) and checking uri.scheme (case-insensitive) would be more robust and self-documenting.
| if (filePath.startsWith('https://') || filePath.startsWith('http://')) { | |
| final uri = Uri.tryParse(filePath.trimLeft()); | |
| final scheme = uri?.scheme.toLowerCase(); | |
| if (scheme == 'https' || scheme == 'http') { |
I noticed while debugging that there was an unnecessary attempted file read when opening a deeplink url as ReceiveSharingIntent would also handle it.
I/flutter (13335): Failed to process incoming file: PathNotFoundException: Cannot open file, path = 'https://lichess.org/iMypvkd1' (OS Error: No such file or directory, errno = 2)