Clipboard: clipboard.flavours leaves out an SVG withheld from a confined caller

Under read roots, clipboard.exportSvg refuses an SVG that would name a
linked image file outside them, but clipboard.flavours still listed
image/svg+xml and the SVG markup as text/plain, and
Session::clipboard_flavours still made them. Both now take Include SVG
Code only when the SVG is not refused; PDF, PNG and a type-only copy's
text are unchanged.
This commit is contained in:
dotCooCoo
2026-11-15 12:58:28 -08:00
parent bb218101c9
commit e030efa52c
4 changed files with 43 additions and 5 deletions
+11 -4
View File
@@ -173,7 +173,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Clipboard Formats",
[],
None,
"{} → {flavours: [mime…]} what Copy offers other apps for the current clipboard, best first, by the Clipboard Handling preferences: text/plain (a type-only copy's text, else the SVG markup with copyAsSvg when the images it embeds total at most 1 MiB), image/svg+xml (copyAsSvg), application/pdf (copyAsPdf), image/png (always; PDF and PNG only for objects with an area); the app publishes them on Copy and Cut",
"{} → {flavours: [mime…]} what Copy offers other apps for the current clipboard, best first, by the Clipboard Handling preferences: text/plain (a type-only copy's text, else the SVG markup with copyAsSvg when the images it embeds total at most 1 MiB), image/svg+xml (copyAsSvg), application/pdf (copyAsPdf), image/png (always; PDF and PNG only for objects with an area); under read roots, SVG and its markup as text are left out when clipboard.exportSvg would refuse; the app publishes them on Copy and Cut",
always,
flavours
),
@@ -369,13 +369,20 @@ impl Session {
/// The MIME types of [`Self::clipboard_flavours`], without making them.
pub fn clipboard_flavour_types(&self) -> Vec<&'static str> {
self.clipboard.flavour_types(self.prefs.copy_as_svg, self.prefs.copy_as_pdf)
self.clipboard.flavour_types(self.clipboard_svg_offered(), self.prefs.copy_as_pdf)
}
/// What Copy offers other apps, best first (see `clipboard.flavours`): [`Clipboard::flavours`]
/// by the Clipboard Handling preferences.
/// by the Clipboard Handling preferences, without the SVG (and the SVG markup as text) that
/// [`Self::clipboard_svg_refused`] withholds from the caller asking now.
pub fn clipboard_flavours(&self) -> Vec<Flavour> {
self.clipboard.flavours(self.prefs.copy_as_svg, self.prefs.copy_as_pdf)
self.clipboard.flavours(self.clipboard_svg_offered(), self.prefs.copy_as_pdf)
}
/// Does Copy offer the SVG: Include SVG Code is on and the SVG is not withheld from the caller
/// asking now.
fn clipboard_svg_offered(&self) -> bool {
self.prefs.copy_as_svg && !self.clipboard_svg_refused()
}
/// Replace the clipboard with `clip`, centred on `p`'s `center` (default: the first
+29
View File
@@ -2117,6 +2117,35 @@ fn confined_clipboard_svg_refuses_a_linked_image_file_outside_the_read_roots() {
assert!(svg.contains(&format!("xlink:href=\"{photo}\"")), "{svg}");
}
/// `clipboard.flavours` and the session's flavors leave out the SVG, and its markup as text, that
/// `clipboard.exportSvg` withholds from a confined caller; the PNG is still listed. The SVG is listed
/// while its image's pixels are held, and for a caller with no read roots.
#[test]
fn confined_clipboard_flavours_leave_out_a_withheld_svg() {
use crate::file_access::{AutomationRoots, confine};
let away = Folder::new("clip-flavours-away");
let home = Folder::new("clip-flavours-home");
let photo = away.file("photo.png");
write(&photo, &png(60, 30, RED));
let mut s = session();
let a = place(&mut s, &photo);
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
s.execute("edit.copy", &json!({})).unwrap();
let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap();
let (text, svg, png) = ("text/plain", "image/svg+xml", "image/png");
let listed = |s: &mut Session| confine(roots.as_ref(), || s.execute("clipboard.flavours", &json!({}))).unwrap()["flavours"].clone();
assert_eq!(listed(&mut s), json!([text, svg, png]));
without_pixels(&mut s, a);
s.execute("edit.copy", &json!({})).unwrap();
assert_eq!(listed(&mut s), json!([png]));
let made = confine(roots.as_ref(), || s.clipboard_flavours());
assert!(made.iter().all(|f| f.mime != svg && f.mime != text), "{:?}", made.iter().map(|f| f.mime).collect::<Vec<_>>());
assert_eq!(confine(roots.as_ref(), || s.clipboard_flavour_types()), [png]);
assert_eq!(s.execute("clipboard.flavours", &json!({})).unwrap()["flavours"], json!([text, svg, png]));
}
/// A confined caller's SVG with Preserve Editing Capabilities is refused while the stored brush
/// library holds an entry that does not read as a brush, or is not a list: the native document
/// carries it as it is, and its links cannot be checked. Without Preserve Editing the SVG is written.