diff --git a/src/app.rs b/src/app.rs index de5cb3a..9d8e0db 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3840,10 +3840,10 @@ impl Application for App { // Check if clipboard has any paste-able content and cache it return clipboard::read_data::().map(|contents_opt| { match contents_opt { - Some(contents) => cosmic::action::app(Message::ClipboardCached( - ClipboardCache::Files(contents), - )), - None => cosmic::action::app(Message::CheckClipboardImage), + Some(contents) if !contents.paths.is_empty() => cosmic::action::app( + Message::ClipboardCached(ClipboardCache::Files(contents)), + ), + _ => cosmic::action::app(Message::CheckClipboardImage), } }); } diff --git a/src/clipboard.rs b/src/clipboard.rs index 637303e..6b0be96 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -128,9 +128,14 @@ impl TryFrom<(Vec, String)> for ClipboardPaste { // Assume the kind is Copy if not provided by the mime type let mut kind = ClipboardKind::Copy; let mut paths = Vec::new(); + match mime.as_str() { "text/uri-list" => { let text = str::from_utf8(&data)?; + let lines = text.lines(); + if text.is_empty() || lines.count() == 0 { + Err(format!("Empty file url"))?; + } for line in text.lines() { let url = Url::parse(line)?; match url.to_file_path() { @@ -141,6 +146,10 @@ impl TryFrom<(Vec, String)> for ClipboardPaste { } "x-special/gnome-copied-files" => { let text = str::from_utf8(&data)?; + let lines = text.lines(); + if text.is_empty() || lines.count() == 0 { + Err(format!("Empty file url"))?; + } for (i, line) in text.lines().enumerate() { if i == 0 { kind = match line {