Merge pull request #7987 from dotCooCoo/fix/clipboard-flavours-confined-svg

Clipboard: clipboard.flavours leaves out an SVG withheld from a confined caller
This commit is contained in:
BFlat
2026-11-16 08:10:45 +07:00
committed by GitHub
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.
+2 -1
View File
@@ -7978,7 +7978,8 @@ Besides SVG, Copy offers other apps PNG and PDF of the copied objects, and their
preferences: `text/plain` (the text of a type-only copy, else the SVG markup with `copyAsSvg` when the images it
embeds total at most 1 MiB, so a paste never reads a photo back as text, #2213), `image/svg+xml`
(`copyAsSvg`), `application/pdf` (`copyAsPdf`) and `image/png` (always; PDF and PNG need objects with an
area). Each one has a query command:
area). For a caller with read roots, the list leaves out `image/svg+xml`, and the SVG markup as `text/plain`, when
`clipboard.exportSvg` would refuse the SVG. Each one has a query command:
`clipboard.exportSvg`, `clipboard.exportText` (null unless every copied object is type), `clipboard.exportPdf`
(a one-page PDF, the page the objects' visual bounds) and `clipboard.exportPng {scale?}` (cropped to the objects,
transparent around them). As in `document.export`, the PDF's and the PNG's replies list their notes in `warnings`
+1
View File
@@ -888,6 +888,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Document replies under `--automation-read-root`: `document.inspect` gives `path` as null for a document file outside the read roots, and `document.json` names a linked image or placed file outside them by its file name alone, without its relative path, size or date, brush art included, leaves out a relative path that leads outside them and a stored brush entry that does not read as a brush, names a data set's image value outside them by its file name, and leaves an Export for Screens folder outside them out of `export_settings`; the document is not changed. `crates/engine/src/tests/placed_document.rs` (`document_replies_leave_out_paths_outside_the_read_roots`, `document_json_checks_brush_art_and_relative_paths_against_the_read_roots`).
- SVG output under `--automation-read-root`: `document.serialize`, `document.export`, `document.exportSelection`, `document.exportForScreens`, `assets.export`, the SVG and SVGZ saves, `file.exportAs` and the SVG Options dialog's Show Code refuse an SVG or SVGZ of a document that links a JavaScript file outside the read roots, before any file or folder is written, with an error that names no file or folder; a URL, a file inside the roots and a relative path that leads inside them are written as stored, and the person at the keyboard exports every link as stored. `crates/engine/src/tests/interactivity.rs` (`confined_svg_output_refuses_a_linked_javascript_file_outside_the_read_roots`, `svg_output_keeps_linked_javascript_files_a_caller_may_read`), `crates/ui-egui/src/tests/automation.rs` (`control_svg_export_refuses_a_linked_javascript_file_outside_the_read_root`), `crates/ui-egui/src/dialogs/svg_options.rs` (`show_code_leaves_out_a_linked_javascript_file_outside_the_read_roots`).
- Linked images in SVG output under `--automation-read-root`: the same outputs, and `clipboard.exportSvg`, refuse an SVG or SVGZ that would name a linked image's file outside the read roots (`images: link`, an image whose pixels the document doesn't hold, or `preserveEditing`), before any file or folder is written, with an error that names no file or folder; Copy in a frame a request drives then puts no SVG on the system clipboard. Embedded pixels, a file inside the roots, a relative path that leads inside them and a URL are written as before, and the person at the keyboard exports every link as stored. The check covers the art drawn for placed documents and leaves out what the file leaves out: hidden art in symbols, patterns and graph designs, opacity masks in SVG Tiny 1.2, and objects drawn as images for effects SVG has no filter for. `crates/engine/src/tests/links.rs` (`confined_svg_output_refuses_a_linked_image_file_outside_the_read_roots`, `svg_output_names_linked_image_files_a_caller_may_read`, `confined_clipboard_svg_refuses_a_linked_image_file_outside_the_read_roots`, `confined_preserve_editing_svg_refuses_a_brush_library_entry_it_cannot_read`, `confined_svg_output_checks_only_the_linked_images_it_writes`, `confined_svg_output_writes_a_colorized_gray_image_without_its_file`, `confined_svg_output_checks_the_images_of_placed_documents`, `confined_svg_output_leaves_hidden_symbol_art_unchecked`, `confined_svg_tiny_output_leaves_opacity_mask_images_unchecked`, `confined_svg_output_checks_the_images_drawn_for_pixel_effects`), `crates/ui-egui/src/tests/automation.rs` (`control_svg_export_refuses_a_linked_image_file_outside_the_read_root`), `crates/ui-egui/src/dialogs/svg_options.rs` (`show_code_leaves_out_a_linked_image_file_outside_the_read_roots`).
- Clipboard flavors under `--automation-read-root`: `clipboard.flavours` leaves out the SVG, and its markup as text, that `clipboard.exportSvg` refuses. `crates/engine/src/tests/links.rs` (`confined_clipboard_flavours_leave_out_a_withheld_svg`).
- Linked-file and font-file searches under `--automation-read-root`: `links.findFiles` and `text.findFontFiles` replies, also later polls and stops of a search another client started, leave out the files found, a link's saved path and the folder searched outside the caller's read roots, and a failed search gives its reason without the path; `image.info` gives `link: null` for a linked file outside them; `text.addFontFiles` gives `folder: null` and the copies' file names when the Fonts folder is outside them. `crates/engine/src/tests/linkfiles.rs`, `crates/engine/src/tests/fontfiles.rs`, `crates/engine/tests/font_folder.rs`.
- Swatch, brush, symbol and graphic style library lists under `--automation-read-root`: every library stays listed, the paths of library files and the user library folder outside the read roots are `null`, a library loaded from outside them is listed and found as `loaded/<file name>` and keeps that id for the session unless a library loaded later without a file shows that id itself, which moves it to the next free `loaded/<file name> (N)`, and the app's own list is not changed. `crates/engine/src/tests/library_roots.rs`.
- Preferences commands under `--automation-read-root`: `prefs.get`, `prefs.list`, `prefs.set` and `prefs.reset` show folder preferences outside the read roots as `null` and leave out an export preset's folder outside them, and the preferences are not changed. `crates/engine/src/tests/prefs_roots.rs`.