mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 13:08:32 +00:00
Merge pull request #7600 from dotCooCoo/fix/confined-exports-script-paths
MCP: confined exports refuse native files that name a linked JavaScript file outside the read roots
This commit is contained in:
@@ -129,9 +129,9 @@ mod commands;
|
||||
mod export_names;
|
||||
mod formats;
|
||||
|
||||
pub(crate) use access::check_images_in;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) use access::list_dir;
|
||||
pub(crate) use access::{check_images_in, check_scripts_of};
|
||||
pub use access::{check_linked_images, check_linked_scripts, write_file_with, write_save_file, write_save_file_with};
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
|
||||
@@ -121,22 +121,54 @@ pub(crate) fn naming_in_message(msg: &str, path: &str, name: &str) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// The error for an SVG of a document that links a JavaScript file outside the read roots.
|
||||
/// The error for a file that would name a JavaScript file the document links outside the read roots.
|
||||
pub(crate) const SCRIPT_OUTSIDE: &str = "a linked JavaScript file is outside the read roots";
|
||||
|
||||
/// `cmd` may write `st`'s document in format `format` (a format id): any format but SVG and SVGZ,
|
||||
/// and those too unless read roots are in force and the document links a JavaScript file outside
|
||||
/// them (`svg_scripts`, a relative path taken from the document's folder; a URL is not checked),
|
||||
/// which the file's `<script>` element would name. The error names no file or folder.
|
||||
pub fn check_linked_scripts(cmd: &str, format: &str, st: &crate::DocState) -> Result<()> {
|
||||
if !matches!(format, "svg" | "svgz") || crate::file_access::current().is_none() {
|
||||
/// `cmd` may write `st`'s document in format `format` (a format id) with options `p` (presets
|
||||
/// written out): always, unless read roots are in force, the document links a JavaScript file
|
||||
/// outside them (`svg_scripts`, a relative path taken from the document's folder; a URL is not
|
||||
/// checked) and the file names it ([`names_linked_scripts`], with the artboards `p` picks counted
|
||||
/// in `st`'s document): an SVG's `<script>` element, or the native document that a native file, a
|
||||
/// `.ai` file, an EPS file or a PDF with Preserve Editing carries. The error names no file or folder.
|
||||
pub fn check_linked_scripts(cmd: &str, format: &str, st: &crate::DocState, p: &Value) -> Result<()> {
|
||||
check_scripts_of(cmd, &st.doc, st.path.as_deref(), || names_linked_scripts(cmd, format, p, st.doc.artboards.len()))
|
||||
}
|
||||
|
||||
/// `doc`, saved at `doc_path`, may be written by `cmd` in a file that names its linked JavaScript
|
||||
/// files when `names` says so: as [`check_linked_scripts`] allows it.
|
||||
pub(crate) fn check_scripts_of(cmd: &str, doc: &vectorcraft_doc::Document, doc_path: Option<&str>, names: impl FnOnce() -> bool) -> Result<()> {
|
||||
if crate::file_access::current().is_none() || !doc.svg_scripts.iter().any(|f| crate::cmd::links::script_hidden(f, doc_path)) || !names() {
|
||||
return Ok(());
|
||||
}
|
||||
let doc_path = st.path.as_deref();
|
||||
if st.doc.svg_scripts.iter().any(|f| crate::cmd::links::script_hidden(f, doc_path)) {
|
||||
return Err(bad(cmd, SCRIPT_OUTSIDE));
|
||||
Err(bad(cmd, SCRIPT_OUTSIDE))
|
||||
}
|
||||
|
||||
/// Does a file of a document with `artboards` artboards, written in format `format` with options
|
||||
/// `p`, name the JavaScript files the document links? SVG, SVGZ, native files, native templates and
|
||||
/// EPS files always do. A `.ai` or `.ait` file does unless it is a legacy version 7 `.ai` file or `p`
|
||||
/// picks only some of the artboards; a PDF does with Preserve Editing on (as its preset, standard and
|
||||
/// options leave it) unless `p` picks only some of the artboards. Neither a `.ai` file nor a PDF
|
||||
/// does when `useArtboards` is false in `p` (one page, the bounds of the art). Options the encoder
|
||||
/// refuses count as naming them.
|
||||
pub(crate) fn names_linked_scripts(cmd: &str, format: &str, p: &Value, artboards: usize) -> bool {
|
||||
use serde::Deserialize;
|
||||
let every_artboard = || {
|
||||
let pick = if p.is_object() { super::ArtboardPick::deserialize(p).ok() } else { Some(super::ArtboardPick::default()) };
|
||||
pick.and_then(|pick| pick.resolve(artboards).ok()).is_none_or(|v| v.is_none_or(|v| v.iter().copied().eq(0..artboards)))
|
||||
};
|
||||
let art_page = || super::encode::use_artboards(cmd, p).is_ok_and(|u| u == Some(false));
|
||||
match format {
|
||||
"svg" | "svgz" | "vectorcraft" | "template" | "eps" => true,
|
||||
"ai" | "ait" => {
|
||||
let legacy = super::format(format).is_some_and(|f| super::legacy_ai::wanted(cmd, f, p).unwrap_or(false));
|
||||
!legacy && !(format == "ai" && art_page()) && every_artboard()
|
||||
}
|
||||
"pdf" => {
|
||||
let editing = super::pdf::settings(cmd, p).ok().is_none_or(|s| s.preserve_editing);
|
||||
editing && !art_page() && every_artboard()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The error for an SVG that would name a linked image's file outside the read roots.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -53,10 +53,10 @@ pub(super) fn export_reads(f: &Format, legacy: bool, key: &str) -> bool {
|
||||
|
||||
pub(super) fn serialize(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let f = writable("document.serialize", Some(text_param(p, "format", "document.serialize")?.unwrap_or("vectorcraft")), None)?;
|
||||
check_linked_scripts("document.serialize", f.id, s.doc()?)?;
|
||||
let unused = unused_option_notes("document.serialize", f, p);
|
||||
let expanded = expand_presets(s, "document.serialize", p)?;
|
||||
let p = with_black_output(s, &expanded);
|
||||
check_linked_scripts("document.serialize", f.id, s.doc()?, &p)?;
|
||||
let (doc, display_doc_title) = source(s, f, &p, "document.serialize")?;
|
||||
let doc = &*doc;
|
||||
let mut q = p.clone();
|
||||
@@ -97,10 +97,10 @@ pub(super) fn export(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
super::check_not_lossy_overwrite(s.doc()?, path, p, "document.export")?;
|
||||
}
|
||||
let f = writable("document.export", text_param(p, "format", "document.export")?, path)?;
|
||||
check_linked_scripts("document.export", f.id, s.doc()?)?;
|
||||
let unused = unused_option_notes("document.export", f, p);
|
||||
let expanded = expand_presets(s, "document.export", p)?;
|
||||
let p = with_black_output(s, &expanded);
|
||||
check_linked_scripts("document.export", f.id, s.doc()?, &p)?;
|
||||
let (doc, display_doc_title) = source(s, f, &p, "document.export")?;
|
||||
let doc = &*doc;
|
||||
let mut q = p.clone();
|
||||
@@ -375,10 +375,11 @@ pub(super) fn export_selection(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
super::check_not_lossy_overwrite(s.doc()?, path, p, C)?;
|
||||
}
|
||||
let f = writable(C, text_param(p, "format", C)?, path)?;
|
||||
check_linked_scripts(C, f.id, s.doc()?)?;
|
||||
let unused = unused_option_notes(C, f, p);
|
||||
let expanded = expand_presets(s, C, p)?;
|
||||
let p = with_black_output(s, &expanded);
|
||||
// The selection is written on one artboard of its own: every artboard, whatever `p` picks.
|
||||
check_linked_scripts(C, f.id, s.doc()?, &without_artboards(&p))?;
|
||||
let (d, bounds) = selection(s, C, f.id == "txt")?;
|
||||
// The selected objects' links are looked for from the document they are in.
|
||||
check_images_in(C, f.id, &d, crate::cmd::links::LinkBase::of(s.doc()?), &without_artboards(&p))?;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -889,7 +889,6 @@ pub(crate) fn job_for(s: &Session, st: &DocState, plan: SavePlan) -> Result<Save
|
||||
|
||||
fn job_for_stamped(s: &Session, st: &DocState, plan: SavePlan, stamped: Option<i64>) -> Result<SaveJob> {
|
||||
let cmd = plan.mode.command();
|
||||
super::check_linked_scripts(cmd, plan.format.id, st)?;
|
||||
let mut own = doc_to_save(st, plan.format);
|
||||
let mut params = plan.options.clone();
|
||||
if is_svg(plan.format) {
|
||||
@@ -934,6 +933,14 @@ fn job_for_stamped(s: &Session, st: &DocState, plan: SavePlan, stamped: Option<i
|
||||
o.insert("range".into(), json!("all"));
|
||||
}
|
||||
}
|
||||
// A saved `.ai` or `.ait` file has the artboards as its pages, whatever `useArtboards` says.
|
||||
let checked = match (¶ms, plan.format.id) {
|
||||
(Value::Object(o), "ai" | "ait") => {
|
||||
std::borrow::Cow::Owned(Value::Object(o.iter().filter(|(k, _)| *k != "useArtboards").map(|(k, v)| (k.clone(), v.clone())).collect()))
|
||||
}
|
||||
_ => std::borrow::Cow::Borrowed(¶ms),
|
||||
};
|
||||
super::check_linked_scripts(cmd, plan.format.id, st, &checked)?;
|
||||
Ok(SaveJob { plan, doc, params, snapshot, source: st.doc.clone(), stamped, boards })
|
||||
}
|
||||
|
||||
@@ -1318,7 +1325,7 @@ pub(super) fn specs() -> Vec<CommandSpec> {
|
||||
"Save Document",
|
||||
[],
|
||||
None,
|
||||
"{path?, format?: vectorcraft|template|pdf|svg|svgz|ai|eps (default: the path's extension, else the document's own format), options?: {…the format's options, see file.formatOptions; default: as last saved}, svg?: {…SVG options} (an SVG save keeps hidden layers, display:none, unless hiddenLayers is false), …the SVG and PDF options given flat instead (an option given flat or in svg and in options with different values is an error), compress?: bool (native, also in options: gzip; default: the useCompression preference; warnings name an option given flat or in options that the file doesn't read: a legacy .ai reads only its own options, and other .ai files don't read outlineText, hiddenObjects, transparentImages or preserveEditing), version?: 4 (3, 2 or 1: for older VectorCraft versions; 1 and 2 are never compressed), preview?: false (embed a PNG of the first artboard, at most 256 px), precision?: 0..9 (native: round path anchors and handles to this many decimal places, a smaller file; colors, transforms and type stay exact; default: exact, and a later save without it writes exactly again), separateArtboards?: false (native and .ai: also save each artboard of `range` to <name>-<artboard>.<ext> beside the file, holding that artboard and the art touching it; the result's files lists every file written), range?: \"1-3, 5\"|\"all\" (default; with separateArtboards), includeLinked?: false (keep linked files' own pixels, not just their previews; they stay linked), embedProfiles?: true (carry the ICC profiles loaded from files that the document is tagged with; opening the file installs them where missing), pdfCompatible?: true (native: also carry a PDF of every artboard; false omits it) | true for .ai (false: blank pages, only the native document; a .ai file's compress, default true, is its compression.compressText), modified?: Unix seconds|null (the File Info modified date, and created date when there is none, a save to a file stamps; default now, recorded in the journal so a replay matches; null: leave the dates)} → {path, format, bytes, warnings, files?: [path…] (the file and its artboards' files), linked?: [path…] (images an SVG links to)}. Save writes one artboard, except a .ai file and EPS (below): a .ai file is a PDF-compatible file of every artboard carrying the native document (preserveEditing always on; PDF options flat or in options), which document.open restores exactly, on the active artboard (the app's, else the one the document opened on; with editingData: false, the first); separateArtboards writes more files, one per artboard. EPS takes the options of document.exportEps: by default one file whose bounding box fits the visible art (the first artboard when no art shows), carrying the whole editable document; useArtboards: true (also when artboard, artboards or range names artboards; file.formatOptions then reports it true) makes the chosen artboard the page, drawn with its background color (without Use Artboards, only the first artboard's page when no art shows has its color), and with two or more chosen the file at the path is the central file of the visible art (again the first artboard when none shows) and each artboard is also written to <name>_<artboard>.eps beside it, holding that artboard; selectedOnly is refused; its PostScript appearance flattens transparency, as EPS requires. Without a path it writes the document's own file in its own format: a document opened from or saved as SVG/PDF/EPS saves as that again (warnings name what the format loses). No path known (never saved, converted from an older version, restored by Data Recovery, or another format) → {dataBase64, format, name, folder?, warnings} and the document stays modified. Under automation read roots, a reply leaves out the document's own file outside them when no path is given (files and linked then name the files by their file names), and a suggested folder outside them; an svg or svgz save (a document whose own format is SVG or SVGZ included) is refused, before any file is written, while the document links a JavaScript file outside them (svgInteractivity; a URL is not checked), or while the file would name a linked image's file outside them (images: link, preserveEditing, or an image whose pixels the document doesn't hold; a URL is not checked), also by file.saveAs and file.saveCopy. A key that no save format takes, beside the path or in options, and an unknown key inside a PDF option's object or svg, are refused. A terminal filesystem permission/read-only refusal returns READ_ONLY_LOCATION: followed by the reason; recovery-copy failures keep their original error. Non-UI callers never open a save panel",
|
||||
"{path?, format?: vectorcraft|template|pdf|svg|svgz|ai|eps (default: the path's extension, else the document's own format), options?: {…the format's options, see file.formatOptions; default: as last saved}, svg?: {…SVG options} (an SVG save keeps hidden layers, display:none, unless hiddenLayers is false), …the SVG and PDF options given flat instead (an option given flat or in svg and in options with different values is an error), compress?: bool (native, also in options: gzip; default: the useCompression preference; warnings name an option given flat or in options that the file doesn't read: a legacy .ai reads only its own options, and other .ai files don't read outlineText, hiddenObjects, transparentImages or preserveEditing), version?: 4 (3, 2 or 1: for older VectorCraft versions; 1 and 2 are never compressed), preview?: false (embed a PNG of the first artboard, at most 256 px), precision?: 0..9 (native: round path anchors and handles to this many decimal places, a smaller file; colors, transforms and type stay exact; default: exact, and a later save without it writes exactly again), separateArtboards?: false (native and .ai: also save each artboard of `range` to <name>-<artboard>.<ext> beside the file, holding that artboard and the art touching it; the result's files lists every file written), range?: \"1-3, 5\"|\"all\" (default; with separateArtboards), includeLinked?: false (keep linked files' own pixels, not just their previews; they stay linked), embedProfiles?: true (carry the ICC profiles loaded from files that the document is tagged with; opening the file installs them where missing), pdfCompatible?: true (native: also carry a PDF of every artboard; false omits it) | true for .ai (false: blank pages, only the native document; a .ai file's compress, default true, is its compression.compressText), modified?: Unix seconds|null (the File Info modified date, and created date when there is none, a save to a file stamps; default now, recorded in the journal so a replay matches; null: leave the dates)} → {path, format, bytes, warnings, files?: [path…] (the file and its artboards' files), linked?: [path…] (images an SVG links to)}. Save writes one artboard, except a .ai file and EPS (below): a .ai file is a PDF-compatible file of every artboard carrying the native document (preserveEditing always on; PDF options flat or in options), which document.open restores exactly, on the active artboard (the app's, else the one the document opened on; with editingData: false, the first); separateArtboards writes more files, one per artboard. EPS takes the options of document.exportEps: by default one file whose bounding box fits the visible art (the first artboard when no art shows), carrying the whole editable document; useArtboards: true (also when artboard, artboards or range names artboards; file.formatOptions then reports it true) makes the chosen artboard the page, drawn with its background color (without Use Artboards, only the first artboard's page when no art shows has its color), and with two or more chosen the file at the path is the central file of the visible art (again the first artboard when none shows) and each artboard is also written to <name>_<artboard>.eps beside it, holding that artboard; selectedOnly is refused; its PostScript appearance flattens transparency, as EPS requires. Without a path it writes the document's own file in its own format: a document opened from or saved as SVG/PDF/EPS saves as that again (warnings name what the format loses). No path known (never saved, converted from an older version, restored by Data Recovery, or another format) → {dataBase64, format, name, folder?, warnings} and the document stays modified. Under automation read roots, a reply leaves out the document's own file outside them when no path is given (files and linked then name the files by their file names), and a suggested folder outside them; an svg or svgz save (a document whose own format is SVG or SVGZ included), and a save whose file carries the native document (vectorcraft, template, eps, ai but a version 7 file, pdf of every artboard with preserveEditing on and useArtboards not false), is refused, before any file is written, while the document links a JavaScript file outside them (svgInteractivity; a URL is not checked), or while the file would name a linked image's file outside them (images: link, preserveEditing, or an image whose pixels the document doesn't hold; a URL is not checked), also by file.saveAs and file.saveCopy. A key that no save format takes, beside the path or in options, and an unknown key inside a PDF option's object or svg, are refused. A terminal filesystem permission/read-only refusal returns READ_ONLY_LOCATION: followed by the reason; recovery-copy failures keep their original error. Non-UI callers never open a save panel",
|
||||
has_doc,
|
||||
|s, p| save(s, SaveMode::Save, p)
|
||||
),
|
||||
@@ -1345,7 +1352,7 @@ pub(super) fn specs() -> Vec<CommandSpec> {
|
||||
"Save as Template…",
|
||||
["File"],
|
||||
None,
|
||||
"{…as document.save} {path? (saved with the format's extension: one naming another format is replaced, and one is added to a name without it), format?: template (default) | ait (also when format is not given and the path ends in .ait), compress?, version?, preview?, precision?} a template that opens as a new untitled document: a native template (.vctemplate), or a PDF-compatible .ait written as a .ai file is (the .ai options and the PDF options, as document.save takes them for .ai; aiVersion 7 is an error); the document is unchanged → {path, format, bytes, warnings}; no path → {dataBase64, format, name: \"<name> template.<ext>\", folder: the Templates folder (preference templatesFolder), warnings}",
|
||||
"{…as document.save} {path? (saved with the format's extension: one naming another format is replaced, and one is added to a name without it), format?: template (default) | ait (also when format is not given and the path ends in .ait), compress?, version?, preview?, precision?} a template that opens as a new untitled document: a native template (.vctemplate), or a PDF-compatible .ait written as a .ai file is (the .ai options and the PDF options, as document.save takes them for .ai; aiVersion 7 is an error); the document is unchanged → {path, format, bytes, warnings}; no path → {dataBase64, format, name: \"<name> template.<ext>\", folder: the Templates folder (preference templatesFolder), warnings}. Under automation read roots, it is refused, before any file is written, while the document links a JavaScript file outside them, as document.save refuses it",
|
||||
has_doc,
|
||||
|s, p| save(s, SaveMode::Template, p)
|
||||
),
|
||||
|
||||
@@ -1089,6 +1089,29 @@ pub(crate) fn with_export_preset(s: &Session, cmd: &str, settings: &mut Map<Stri
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Does the file of `item` that row `r` writes carry the native document, and with it the
|
||||
/// JavaScript files the document links ([`super::access::names_linked_scripts`])? A PDF holds the
|
||||
/// artboards it is written with: those of `single` (Export PDFs As › Single file), every artboard
|
||||
/// (Full Document), else the item's artboard of its document.
|
||||
fn names_scripts(item: &Item, r: &Row, single: Option<&[usize]>) -> bool {
|
||||
if r.format.id != "pdf" {
|
||||
return super::access::names_linked_scripts(C, r.format.id, &r.options, item.doc.artboards.len());
|
||||
}
|
||||
let (doc, options) = match (single, &item.every_artboard) {
|
||||
(Some(boards), _) => {
|
||||
let mut options = r.options.clone();
|
||||
options["range"] = json!(boards.iter().map(|b| (b + 1).to_string()).collect::<Vec<_>>().join(", "));
|
||||
(&item.doc, options)
|
||||
}
|
||||
(None, Some(all)) => (all, r.options.clone()),
|
||||
(None, None) => match r.options_for(item.region, item.artboard) {
|
||||
Ok(options) => (&item.doc, options),
|
||||
Err(_) => return true,
|
||||
},
|
||||
};
|
||||
super::access::names_linked_scripts(C, "pdf", &options, doc.artboards.len())
|
||||
}
|
||||
|
||||
/// Every chosen artboard (asset, layer, selected object) in every format row, one file each (a PDF
|
||||
/// holds its artboard alone), or with `fullDocument` one file per row (a PDF of every artboard,
|
||||
/// else the bounds of all art). Items that share a name get `-2`, `-3`… instead of overwriting, and
|
||||
@@ -1105,10 +1128,6 @@ pub(crate) fn export(s: &mut Session, p: &Value, asked: &Value) -> Result<Value>
|
||||
o.one_source()?;
|
||||
// `<filename>`: the document's file, as Save names it, or its title before it is saved.
|
||||
let st = s.doc()?;
|
||||
// Before the folder is made or any row is written.
|
||||
for r in &rows {
|
||||
super::check_linked_scripts(C, r.format.id, st)?;
|
||||
}
|
||||
let naming = Naming::of(&o, st.path.as_deref().unwrap_or(&st.doc.title))?;
|
||||
let selection = o.selection_mode()?;
|
||||
let selected = if selection.is_some() { selected_artwork(s)? } else { vec![] };
|
||||
@@ -1125,6 +1144,10 @@ pub(crate) fn export(s: &mut Session, p: &Value, asked: &Value) -> Result<Value>
|
||||
};
|
||||
let crop = rows.iter().any(|r| r.format.id != "pdf");
|
||||
let items = items(&doc, &o, selection, &selected, &naming.filename, crop, true)?;
|
||||
// Before the folder is made or any row is written, with the artboards each file holds.
|
||||
let single: Option<Vec<usize>> = items.iter().map(|i| i.artboard).collect::<Option<Vec<_>>>().filter(|a| naming.single_pdf && a.len() > 1);
|
||||
let st = s.doc()?;
|
||||
super::check_scripts_of(C, &st.doc, st.path.as_deref(), || rows.iter().any(|r| items.iter().any(|i| names_scripts(i, r, single.as_deref()))))?;
|
||||
// The file each item writes for each SVG row, before the folder is made or any row is written.
|
||||
let base = crate::cmd::links::LinkBase::of(s.doc()?);
|
||||
for r in rows.iter().filter(|r| matches!(r.format.id, "svg" | "svgz")) {
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Package",
|
||||
[],
|
||||
None,
|
||||
"{folder?, name?: (default: \"<document> Folder\"), copyLinks?: true, linksFolder?: true (the linked files go in Links/, else next to the document), relink?: true (the packaged document links to the copies), copyFonts?: true (the fonts its type uses go in Fonts/; fonts whose licence doesn't allow embedding are left out), report?: true (<document> Report.txt)} copy the saved document as it is now into folder/name as <document>.vectorcraft with its linked files and fonts; the open document doesn't change → {folder, files: [paths relative to folder/name], links, fonts (counts copied), missingLinks: [file names not found], skippedFonts: [{font, reason}], warnings: [nested files copied unchanged or cycles/depth stopped]}; no folder → the same with {name: \"<name>.zip\", dataBase64} (a zip of the files in <name>/) instead of folder. The warnings and the report name a file outside the automation read roots by its file name",
|
||||
"{folder?, name?: (default: \"<document> Folder\"), copyLinks?: true, linksFolder?: true (the linked files go in Links/, else next to the document), relink?: true (the packaged document links to the copies), copyFonts?: true (the fonts its type uses go in Fonts/; fonts whose licence doesn't allow embedding are left out), report?: true (<document> Report.txt)} copy the saved document as it is now into folder/name as <document>.vectorcraft with its linked files and fonts; the open document doesn't change → {folder, files: [paths relative to folder/name], links, fonts (counts copied), missingLinks: [file names not found], skippedFonts: [{font, reason}], warnings: [nested files copied unchanged or cycles/depth stopped]}; no folder → the same with {name: \"<name>.zip\", dataBase64} (a zip of the files in <name>/) instead of folder. The warnings and the report name a file outside the automation read roots by its file name. Under automation read roots, the package is refused, before any file is written, while the document, or a linked native document or a linked PDF, .ai or EPS file's native document, links a JavaScript file outside them (svgInteractivity; a URL is not checked)",
|
||||
has_doc,
|
||||
package
|
||||
)]
|
||||
@@ -113,6 +113,30 @@ thread_local! {
|
||||
pub(crate) static PARTS_READ: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// The native document that the linked file `name` (`bytes`) is, or carries as the editing data of
|
||||
/// a PDF, `.ai` or EPS file; `None` for other files and for data that can't be read.
|
||||
fn carried_document(name: &str, bytes: &[u8]) -> Option<Document> {
|
||||
if super::place::document::is_native(name, bytes) {
|
||||
return vectorcraft_format::load_file(bytes).ok().map(|f| f.doc);
|
||||
}
|
||||
let data =
|
||||
if super::place::document::is_pdf(name, bytes) { vectorcraft_pdf::editing(bytes).map(|e| e.data) } else { vectorcraft_eps::native(bytes) };
|
||||
vectorcraft_format::load(&data?).ok()
|
||||
}
|
||||
|
||||
/// Under read roots, the linked file `name` (`bytes`, found at `path`) is copied only when the
|
||||
/// native document it is or carries ([`carried_document`]) links no JavaScript file outside them (a
|
||||
/// relative path taken from the file's folder): the copy would name it.
|
||||
fn check_carried_scripts(name: &str, bytes: &[u8], path: &str) -> Result<()> {
|
||||
if crate::file_access::current().is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
match carried_document(name, bytes) {
|
||||
Some(carried) => super::fileio::check_scripts_of(C, &carried, Some(path), || true),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The fonts of the type on `pages` of the PDF or `.ai` file `name` (`bytes`, found at `path`);
|
||||
/// none for other files.
|
||||
fn page_fonts(name: &str, bytes: &[u8], path: &str, pages: &PlacedPages) -> BTreeSet<super::fonts::UsedFont> {
|
||||
@@ -291,6 +315,7 @@ impl<'a> Collector<'a> {
|
||||
// read from its editing data links are copied beside it.
|
||||
let pages = placed.get(&file.path);
|
||||
let placed_file = pages.is_some();
|
||||
check_carried_scripts(&file.name, &bytes, found_path)?;
|
||||
if placed_file && let Some(mut art) = super::place::document::editing_data(&file.name, &bytes) {
|
||||
if depth >= vectorcraft_doc::placed_document::MAX_DEPTH {
|
||||
self.warn(&mut lines, format!("{shown}: nesting limit reached; copied unchanged without collecting its own links"));
|
||||
@@ -471,6 +496,8 @@ fn prepare(s: &mut Session, p: &Value) -> Result<Package> {
|
||||
let given_name = text_param(p, "name", C)?;
|
||||
let folder = text_param(p, "folder", C)?;
|
||||
let doc_path = s.doc()?.path.clone().ok_or_else(|| bad(C, "save the document first: Package collects a saved document"))?;
|
||||
// Before anything is collected or written, here where the request's read roots are in force.
|
||||
super::fileio::check_linked_scripts(C, "vectorcraft", s.doc()?, &Value::Null)?;
|
||||
let stem = Path::new(&doc_path).file_stem().map_or_else(|| "Untitled".into(), |s| s.to_string_lossy().into_owned());
|
||||
let name = given_name.map_or_else(|| format!("{stem} Folder"), str::to_string);
|
||||
if name.trim().is_empty() || name == "." || name == ".." || name.contains(['/', '\\', ':', '*', '?', '"', '<', '>', '|']) {
|
||||
|
||||
@@ -341,3 +341,139 @@ fn svg_output_keeps_linked_javascript_files_a_caller_may_read() {
|
||||
let text = run(&mut s, "document.serialize", json!({"format": "svg"}))["text"].as_str().unwrap().to_string();
|
||||
assert!(text.contains(&format!("<script xlink:href=\"{outside}\"/>")), "{text}");
|
||||
}
|
||||
|
||||
/// The JavaScript files that the native document a `document.serialize` reply carries links.
|
||||
fn carried_scripts(r: &Value) -> Vec<String> {
|
||||
let bytes = vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap();
|
||||
let native = if bytes.starts_with(b"%PDF") { vectorcraft_pdf::editing(&bytes).expect("editing data").data } else { bytes };
|
||||
vectorcraft_format::load(&native).unwrap().svg_scripts
|
||||
}
|
||||
|
||||
/// A caller confined to read roots: every output that carries the native document (a native file
|
||||
/// or template, a `.ai` or EPS file, a PDF with Preserve Editing, a package) of a document that
|
||||
/// links a JavaScript file outside them is refused before a file or folder is written, with an
|
||||
/// error that names no file or folder, and the document keeps the link.
|
||||
#[test]
|
||||
fn confined_native_output_refuses_a_linked_javascript_file_outside_the_read_roots() {
|
||||
let away = Folder::new("native-script-away");
|
||||
let home = Folder::new("native-script-home");
|
||||
let script = away.file("menu.js");
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 10.0);
|
||||
run(&mut s, "svgInteractivity.addFile", json!({"file": script}));
|
||||
run(&mut s, "assets.add", json!({"ids": [a.0]}));
|
||||
let own = home.file("own.vectorcraft");
|
||||
run(&mut s, "file.saveAs", json!({"path": own}));
|
||||
let before = std::fs::read(&own).unwrap();
|
||||
rect(&mut s, 50.0);
|
||||
let roots = crate::file_access::AutomationRoots::new(&[&home.0], &[&home.0]).unwrap().unwrap();
|
||||
let hidden = [away.0.to_string_lossy().into_owned(), home.0.to_string_lossy().into_owned(), "menu.js".to_string()];
|
||||
let refused = |s: &mut Session, cmd: &str, p: Value| {
|
||||
let e = crate::file_access::confine(Some(&roots), || s.execute(cmd, &p)).expect_err(cmd);
|
||||
assert!(matches!(e, EngineError::BadParams { .. }), "{cmd} {p}: {e:?}");
|
||||
let e = e.to_string();
|
||||
assert!(e.contains("a linked JavaScript file is outside the read roots"), "{cmd} {p}: {e}");
|
||||
for h in &hidden {
|
||||
assert!(!e.contains(h.as_str()), "{cmd} {p} names {h}: {e}");
|
||||
}
|
||||
};
|
||||
let file = |name: &str| home.file(name);
|
||||
let out = file("out");
|
||||
refused(&mut s, "document.serialize", json!({}));
|
||||
for format in ["vectorcraft", "template", "pdf", "ai", "eps"] {
|
||||
refused(&mut s, "document.serialize", json!({"format": format}));
|
||||
refused(&mut s, "document.export", json!({"format": format}));
|
||||
refused(&mut s, "document.export", json!({"format": format, "selectedOnly": true}));
|
||||
refused(&mut s, "document.exportSelection", json!({"format": format}));
|
||||
}
|
||||
// Every artboard picked, and Preserve Editing asked for.
|
||||
refused(&mut s, "document.serialize", json!({"format": "pdf", "range": "1", "preserveEditing": true}));
|
||||
refused(&mut s, "document.serialize", json!({"format": "ai", "artboards": [0], "pdfCompatible": false}));
|
||||
refused(&mut s, "document.export", json!({"format": "pdf", "path": file("export.pdf")}));
|
||||
refused(&mut s, "document.export", json!({"format": "ai", "path": file("export.ai")}));
|
||||
refused(&mut s, "document.export", json!({"format": "eps", "path": file("export.eps")}));
|
||||
refused(&mut s, "document.export", json!({"format": "vectorcraft", "path": file("export.vectorcraft")}));
|
||||
refused(&mut s, "document.exportPdf", json!({}));
|
||||
refused(&mut s, "document.exportPdf", json!({"path": file("direct.pdf")}));
|
||||
refused(&mut s, "document.exportEps", json!({"path": file("direct.eps")}));
|
||||
refused(&mut s, "document.save", json!({}));
|
||||
refused(&mut s, "document.save", json!({"path": file("save.pdf")}));
|
||||
refused(&mut s, "file.saveAs", json!({"path": file("save-as.ai")}));
|
||||
// A saved `.ai` file has the artboards as its pages, whatever `useArtboards` says.
|
||||
refused(&mut s, "file.saveAs", json!({"path": file("save-as-art.ai"), "useArtboards": false}));
|
||||
refused(&mut s, "file.saveAs", json!({"path": file("save-as.eps")}));
|
||||
refused(&mut s, "file.saveCopy", json!({"path": file("copy.vectorcraft")}));
|
||||
refused(&mut s, "file.saveAsTemplate", json!({}));
|
||||
refused(&mut s, "file.saveAsTemplate", json!({"format": "ait"}));
|
||||
refused(&mut s, "document.exportForScreens", json!({"folder": out, "formats": [{"format": "png"}, {"format": "vectorcraft"}]}));
|
||||
refused(&mut s, "document.exportForScreens", json!({"zip": true, "formats": [{"format": "pdf", "preserveEditing": true}]}));
|
||||
refused(&mut s, "assets.export", json!({"folder": out, "formats": [{"format": "ai"}]}));
|
||||
refused(&mut s, "assets.export", json!({"folder": out, "formats": [{"format": "eps"}]}));
|
||||
refused(&mut s, "file.package", json!({"folder": out}));
|
||||
refused(&mut s, "file.package", json!({}));
|
||||
assert_eq!(std::fs::read(&own).unwrap(), before, "the document's own file is left as it was");
|
||||
let written: Vec<_> = std::fs::read_dir(&home.0).unwrap().map(|e| e.unwrap().file_name()).collect();
|
||||
assert_eq!(written, ["own.vectorcraft"]);
|
||||
assert_eq!(s.doc().unwrap().doc.svg_scripts, [script]);
|
||||
}
|
||||
|
||||
/// A confined caller still writes the outputs that carry no native document (a PDF without
|
||||
/// Preserve Editing, a PDF or `.ai` file of the art's bounds or of some artboards, a legacy `.ai`
|
||||
/// file, an image), and
|
||||
/// native outputs that link only JavaScript files it may read keep them as stored. A caller without
|
||||
/// roots writes a file outside them too.
|
||||
#[test]
|
||||
fn confined_output_without_the_document_or_with_scripts_the_caller_may_read_is_written() {
|
||||
let away = Folder::new("native-script-kept-away");
|
||||
let home = Folder::new("native-script-kept-home");
|
||||
let outside = away.file("menu.js");
|
||||
let mut s = session();
|
||||
rect(&mut s, 10.0);
|
||||
run(&mut s, "artboard.new", json!({"x": 200, "y": 0, "width": 100, "height": 100}));
|
||||
run(&mut s, "svgInteractivity.addFile", json!({"file": outside}));
|
||||
let roots = crate::file_access::AutomationRoots::new(&[&home.0], &[&home.0]).unwrap().unwrap();
|
||||
let written = |s: &mut Session, cmd: &str, p: Value| {
|
||||
crate::file_access::confine(Some(&roots), || s.execute(cmd, &p)).unwrap_or_else(|e| panic!("{cmd} {p}: {e}"))
|
||||
};
|
||||
for p in [
|
||||
json!({"format": "pdf", "preserveEditing": false}),
|
||||
json!({"format": "pdf", "useArtboards": false}),
|
||||
json!({"format": "pdf", "range": "2"}),
|
||||
json!({"format": "ai", "artboards": [1]}),
|
||||
json!({"format": "ai", "useArtboards": false}),
|
||||
json!({"format": "ai", "aiVersion": "7"}),
|
||||
json!({"format": "png"}),
|
||||
] {
|
||||
written(&mut s, "document.serialize", p);
|
||||
}
|
||||
written(&mut s, "document.exportPdf", json!({"preserveEditing": false}));
|
||||
written(&mut s, "document.exportForScreens", json!({"zip": true, "formats": [{"format": "pdf"}]}));
|
||||
// A PDF of each artboard leaves the editing data out: it holds one of the two.
|
||||
written(&mut s, "document.exportForScreens", json!({"zip": true, "formats": [{"format": "pdf", "preserveEditing": true}]}));
|
||||
let refused = |s: &mut Session, p: Value| {
|
||||
let e = crate::file_access::confine(Some(&roots), || s.execute("document.exportForScreens", &p)).expect_err("refused").to_string();
|
||||
assert!(e.contains("a linked JavaScript file is outside the read roots"), "{p}: {e}");
|
||||
};
|
||||
// One PDF of both artboards, and Full Document's PDF of every artboard, carry it.
|
||||
refused(&mut s, json!({"zip": true, "pdfs": "single", "formats": [{"format": "pdf", "preserveEditing": true}]}));
|
||||
refused(&mut s, json!({"zip": true, "fullDocument": true, "formats": [{"format": "pdf", "preserveEditing": true}]}));
|
||||
// Without roots, the native document keeps a file outside them.
|
||||
let r = run(&mut s, "document.serialize", json!({}));
|
||||
assert_eq!(carried_scripts(&r), [outside.as_str()]);
|
||||
// Files the caller may read: inside the read roots, relative to the document's folder, a URL.
|
||||
let inside = home.file("menu.js");
|
||||
let url = "https://example.com/scripts/menu.js";
|
||||
let kept = [inside.as_str(), "lib/tools.js", url];
|
||||
let mut s = session();
|
||||
rect(&mut s, 10.0);
|
||||
for file in kept {
|
||||
run(&mut s, "svgInteractivity.addFile", json!({"file": file}));
|
||||
}
|
||||
run(&mut s, "file.saveAs", json!({"path": home.file("doc.vectorcraft")}));
|
||||
for format in ["vectorcraft", "pdf"] {
|
||||
let r = written(&mut s, "document.serialize", json!({"format": format}));
|
||||
assert_eq!(carried_scripts(&r), kept, "{format}");
|
||||
}
|
||||
written(&mut s, "document.exportPdf", json!({"path": home.file("doc.pdf")}));
|
||||
written(&mut s, "file.package", json!({}));
|
||||
}
|
||||
|
||||
@@ -351,6 +351,60 @@ fn a_confined_package_names_files_outside_the_read_root_by_name() {
|
||||
assert!(info.to_string().contains(&dir.file("art/red.png")), "the person's: {info}");
|
||||
}
|
||||
|
||||
/// A confined request packages no document that links, or places a native document or a PDF with
|
||||
/// Preserve Editing that links, a JavaScript file outside its read roots: the package is refused
|
||||
/// before anything is written, with an error that names no file or folder. A JavaScript file inside
|
||||
/// them is packaged, and so is one outside them when the person packages.
|
||||
#[test]
|
||||
fn a_confined_package_refuses_a_linked_javascript_file_outside_the_read_root() {
|
||||
let away = Folder::new("package-script-away");
|
||||
let home = Folder::new("package-script-home");
|
||||
let script = away.file("menu.js");
|
||||
let roots = crate::file_access::AutomationRoots::new(&[&home.0], &[&home.0]).unwrap().unwrap();
|
||||
let hidden = [away.0.to_string_lossy().into_owned(), home.0.to_string_lossy().into_owned(), "menu.js".to_string()];
|
||||
let refused = |s: &mut Session, p: Value| {
|
||||
let e = crate::file_access::confine(Some(&roots), || s.execute("file.package", &p)).expect_err("refused");
|
||||
assert!(matches!(e, EngineError::BadParams { .. }), "{p}: {e:?}");
|
||||
let e = e.to_string();
|
||||
assert!(e.contains("a linked JavaScript file is outside the read roots"), "{p}: {e}");
|
||||
for h in &hidden {
|
||||
assert!(!e.contains(h.as_str()), "{p} names {h}: {e}");
|
||||
}
|
||||
};
|
||||
let mut part = session();
|
||||
run(&mut part, "shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 30}));
|
||||
run(&mut part, "svgInteractivity.addFile", json!({"file": script}));
|
||||
std::fs::create_dir_all(home.0.join("art")).unwrap();
|
||||
let native = home.file("art/part.vectorcraft");
|
||||
save(&mut part, &native);
|
||||
let r = run(&mut part, "document.serialize", json!({"format": "pdf"}));
|
||||
let pdf = home.file("art/part.pdf");
|
||||
write(&pdf, &vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap());
|
||||
let out = home.file("out");
|
||||
refused(&mut part, json!({"folder": out}));
|
||||
refused(&mut part, json!({}));
|
||||
for placed in [&native, &pdf] {
|
||||
let mut s = session();
|
||||
let r = run(&mut s, "file.place", json!({"path": placed, "link": true}));
|
||||
assert_eq!(r["linked"], true, "{r}");
|
||||
save(&mut s, &home.file("poster.vectorcraft"));
|
||||
refused(&mut s, json!({"folder": out}));
|
||||
refused(&mut s, json!({}));
|
||||
assert!(!std::path::Path::new(&out).exists(), "{placed}");
|
||||
// The person's package copies it.
|
||||
assert_eq!(run(&mut s, "file.package", json!({}))["links"], 1, "{placed}");
|
||||
}
|
||||
// A JavaScript file inside the read roots.
|
||||
run(&mut part, "svgInteractivity.removeFile", json!({"file": script}));
|
||||
run(&mut part, "svgInteractivity.addFile", json!({"file": home.file("menu.js")}));
|
||||
save(&mut part, &native);
|
||||
let mut s = session();
|
||||
run(&mut s, "file.place", json!({"path": native, "link": true}));
|
||||
save(&mut s, &home.file("poster.vectorcraft"));
|
||||
let r = crate::file_access::confine(Some(&roots), || s.execute("file.package", &json!({"folder": out}))).unwrap();
|
||||
assert_eq!(r["links"], 1, "{r}");
|
||||
}
|
||||
|
||||
/// A missing link stored as a path relative to the document names a file inside a confined
|
||||
/// request's read root: the package report and Document Info give its stored path.
|
||||
#[test]
|
||||
|
||||
@@ -1390,7 +1390,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"file.exportAs",
|
||||
"Export As…",
|
||||
"",
|
||||
"{format?, useArtboards?, range?} opens Export As (then the format's options); with {path, …document.export options} writes the file(s) → {path, warnings, files?}; exportSelection: true writes the selection alone, cropped to it, as document.exportSelection writes it (artboard options are not used); under automation read roots, an SVG or SVGZ is refused while the document links a JavaScript file outside them, or while the file would name a linked image's file outside them, as document.export refuses it",
|
||||
"{format?, useArtboards?, range?} opens Export As (then the format's options); with {path, …document.export options} writes the file(s) → {path, warnings, files?}; exportSelection: true writes the selection alone, cropped to it, as document.exportSelection writes it (artboard options are not used); under automation read roots, an SVG or SVGZ, or a file that carries the native document, is refused while the document links a JavaScript file outside them, or while the file would name a linked image's file outside them, as document.export refuses it",
|
||||
),
|
||||
(
|
||||
"ui.fileInfoDialog",
|
||||
|
||||
@@ -300,7 +300,7 @@ fn code_view(app: &VectorcraftApp, ui: &mut egui::Ui, d: &Dialog) {
|
||||
None => {
|
||||
const MAX: usize = 200_000;
|
||||
let params = json!({ "svg": opts });
|
||||
let encoded = vectorcraft_engine::cmd::fileio::check_linked_scripts("document.export", "svg", st).and_then(|()| {
|
||||
let encoded = vectorcraft_engine::cmd::fileio::check_linked_scripts("document.export", "svg", st, ¶ms).and_then(|()| {
|
||||
let selected;
|
||||
let doc = if selection {
|
||||
selected = vectorcraft_engine::cmd::fileio::selection_doc(st, "document.exportSelection", false)?.0;
|
||||
|
||||
@@ -73,7 +73,9 @@ pub fn export(app: &mut VectorcraftApp, format: Option<&str>, path: Option<Strin
|
||||
// A `.ai` file names the view's active artboard.
|
||||
remember_active_artboard(app);
|
||||
let st = app.session.active().ok_or("no document")?;
|
||||
fileio::check_linked_scripts("file.exportAs", f.id, st).map_err(|e| e.to_string())?;
|
||||
// With a saved PDF preset written out, as the encoder reads it.
|
||||
let checked = fileio::pdf::expand_preset(&app.session, "file.exportAs", params).unwrap_or(std::borrow::Cow::Borrowed(params));
|
||||
fileio::check_linked_scripts("file.exportAs", f.id, st, &checked).map_err(|e| e.to_string())?;
|
||||
let doc = if selection {
|
||||
std::sync::Arc::new(fileio::selection_doc(st, "document.exportSelection", f.id == "txt").map_err(|e| e.to_string())?.0)
|
||||
} else {
|
||||
|
||||
@@ -1391,7 +1391,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"file.exportAs",
|
||||
"Export As…",
|
||||
"",
|
||||
"{format?, useArtboards?, range?} opens Export As (then the format's options); with {path, …document.export options} writes the file(s) → {path, warnings, files?}; exportSelection: true writes the selection alone, cropped to it, as document.exportSelection writes it (artboard options are not used); under automation read roots, an SVG or SVGZ is refused while the document links a JavaScript file outside them, or while the file would name a linked image's file outside them, as document.export refuses it",
|
||||
"{format?, useArtboards?, range?} opens Export As (then the format's options); with {path, …document.export options} writes the file(s) → {path, warnings, files?}; exportSelection: true writes the selection alone, cropped to it, as document.exportSelection writes it (artboard options are not used); under automation read roots, an SVG or SVGZ, or a file that carries the native document, is refused while the document links a JavaScript file outside them, or while the file would name a linked image's file outside them, as document.export refuses it",
|
||||
),
|
||||
(
|
||||
"ui.fileInfoDialog",
|
||||
|
||||
@@ -272,6 +272,39 @@ fn control_svg_export_refuses_a_linked_javascript_file_outside_the_read_root() {
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// `app.export`, and `file.exportAs` run as a command, write no file that carries the native
|
||||
/// document (a PDF with Preserve Editing, a native file, a `.ai` or EPS file) of a document that
|
||||
/// links a JavaScript file outside the read root, and the error names no file or folder; a PDF
|
||||
/// without Preserve Editing is written, and the person at the keyboard exports the native file.
|
||||
#[test]
|
||||
fn control_native_export_refuses_a_linked_javascript_file_outside_the_read_root() {
|
||||
let (mut app, tx, base) = confined("native-script");
|
||||
app.run("file.new", json!({"width": 100, "height": 50})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
|
||||
let script = s(base.join("outside/menu.js"));
|
||||
app.run("svgInteractivity.addFile", json!({"file": script})).unwrap();
|
||||
let out = |name: &str| s(base.join("out").join(name));
|
||||
for (method, params) in [
|
||||
("app.export", json!({"path": out("a.pdf"), "wait": true})),
|
||||
("app.export", json!({"path": out("a.ai"), "wait": true})),
|
||||
("app.export", json!({"format": "eps"})),
|
||||
("engine.execute", json!({"command": "file.exportAs", "params": {"path": out("a.vectorcraft"), "format": "vectorcraft"}})),
|
||||
] {
|
||||
let r = request(&mut app, &tx, method, params.clone());
|
||||
let e = r["error"].as_str().unwrap_or_default();
|
||||
assert!(e.contains("a linked JavaScript file is outside the read roots"), "{method} {params}: {r}");
|
||||
assert!(!e.contains("menu.js") && !e.contains(&s(base.clone())), "{method} {params}: {r}");
|
||||
}
|
||||
assert_eq!(std::fs::read_dir(base.join("out")).unwrap().count(), 0, "nothing written");
|
||||
let r = request(&mut app, &tx, "app.export", json!({"path": out("b.pdf"), "preserveEditing": false, "wait": true}));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
// The person at the keyboard isn't confined.
|
||||
app.run("file.exportAs", json!({"path": out("a.vectorcraft"), "format": "vectorcraft"})).unwrap();
|
||||
let native = vectorcraft_format::load(&std::fs::read(out("a.vectorcraft")).unwrap()).unwrap();
|
||||
assert_eq!(native.svg_scripts, [script]);
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// `app.export`, and `file.exportAs` run as a command, write no SVG that would name a linked
|
||||
/// image's file outside the read root (Images: Link, Preserve Editing Capabilities), and the error
|
||||
/// names no file or folder. Embedded pixels are written; the person at the keyboard exports the
|
||||
|
||||
+13
-3
@@ -244,7 +244,13 @@ the suite) keep the agent to the folders you give it:
|
||||
`export`), `document.exportSelection`, `document.exportForScreens` and `assets.export` (before the folder is
|
||||
made or any row is written), `document.save`, `file.save`, `file.saveAs` and `file.saveCopy` (also a save
|
||||
without a path of a document whose own format is SVG or SVGZ), `file.exportAs`, and the SVG Options dialog's
|
||||
Show Code. A file given as another URL (`https://…`) is not checked. The document keeps the link, and the
|
||||
Show Code. The same error refuses, before any file is written, every output that carries the native document,
|
||||
which holds the link: a native file or template, an EPS file, a `.ai` or `.ait` file of every artboard (not a
|
||||
legacy version 7 `.ai` file; a save of a `.ai` file always has every artboard), a PDF of every artboard with
|
||||
Preserve Editing on (also from `document.exportPdf`), and `file.package` (also when a linked native document,
|
||||
or the native document a linked PDF, `.ai` or EPS file carries, links such a file). A PDF or `.ai` file of
|
||||
some of the artboards or of the art's bounds (`useArtboards: false`), a PDF without Preserve Editing, and an
|
||||
image are written as before. A file given as another URL (`https://…`) is not checked. The document keeps the link, and the
|
||||
person at the keyboard exports it as stored.
|
||||
- The same SVG and SVGZ outputs are refused with "a linked image file is outside the read roots", which names no
|
||||
file or folder, when the file would name a linked image's file outside the read roots (a path, a `file:` URL,
|
||||
@@ -1464,7 +1470,9 @@ Preserve Editing (`preserveEditing`, on in the `VectorCraft Default` preset) emb
|
||||
an embedded file (`vectorcraft-editing.vectorcraft`; files named `drawcraft-editing.drawcraft` are read too) with a
|
||||
hash of the pages it was written with. `open_file` / `document.open` of such a PDF, `.ai` or `.ait` (no `pages` picked) restores the
|
||||
document exactly (`restored: true`); when another app changed the pages, or the data can't be read, the artwork is
|
||||
imported instead and the first warning says why. Choosing a standard turns it off (PDF/A refuses it). Save to a `.ai`
|
||||
imported instead and the first warning says why. Choosing a standard turns it off (PDF/A refuses it). Under automation
|
||||
read roots, a PDF that carries the native document is refused while the document links a JavaScript file outside them
|
||||
(see [Confining file access](#confining-file-access)). Save to a `.ai`
|
||||
path (`document.save {path: "art.ai"}` or `{format: "ai"}`) writes a PDF-compatible file that always carries the
|
||||
document, takes the PDF options and keeps its path when reopened, so Save writes `.ai` again; a `.ait` opens untitled.
|
||||
The restored document opens on the artboard its editing copy names as active. A file saved with `editingData: false` has
|
||||
@@ -8300,7 +8308,9 @@ type uses in `Fonts/` (fonts whose licence doesn't allow embedding are listed in
|
||||
the copies (each file copied once); one that can't be read is copied as it is, and a cycle of placed documents or one
|
||||
past the nesting limit stops there, each with a line in `warnings` and the report. A `folder/name` where a packaged file
|
||||
would replace the document or one of its linked files (the document's own folder, say) is an error, and nothing is
|
||||
written. Every option defaults to true. An option that is not true or false, or a `folder` or `name` that is not a
|
||||
written. Under automation read roots, the package is refused, and nothing is written, while the document, a linked
|
||||
native document or the native document a linked PDF, `.ai` or EPS file carries links a JavaScript file outside them
|
||||
(see [Confining file access](#confining-file-access)). Every option defaults to true. An option that is not true or false, or a `folder` or `name` that is not a
|
||||
string, is an error naming the key, and nothing is written; null is the same as leaving the key out. Without `folder` (the web, or an agent that wants the bytes) the
|
||||
result carries the same files as a zip (`{name: "<name>.zip", dataBase64}`, entries under `<name>/`).
|
||||
|
||||
|
||||
@@ -895,6 +895,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Link replies under `--automation-read-root`: `links.list`, `links.check`, `links.info` and `document.open`'s link rows leave out the path, found path and folder of a linked file outside the read roots, and the stored size and date of it in `links.info`; each row keeps its id, file name and status, and the document's links are not changed. `crates/engine/src/tests/linkspanel.rs` (`link_paths_outside_the_read_roots_are_left_out`), `crates/engine/src/tests/placed_document.rs` (`link_info_leaves_out_a_placed_documents_path_outside_the_read_roots`).
|
||||
- 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`).
|
||||
- Native document output under `--automation-read-root`: the same commands, `document.exportPdf` and `file.package` refuse a native file or template, an EPS file, a `.ai` or `.ait` file of every artboard (not a legacy version 7 file), a PDF of every artboard with Preserve Editing on, and a package, of a document that links a JavaScript file outside the read roots, before any file or folder is written, with the same error; a package is refused too when a linked native document, or the native document a linked PDF, `.ai` or EPS file carries, links one. A PDF or `.ai` file of some artboards or of the art's bounds, a PDF without Preserve Editing and an image are written, and linked files the caller may read are kept as stored. `crates/engine/src/tests/interactivity.rs` (`confined_native_output_refuses_a_linked_javascript_file_outside_the_read_roots`, `confined_output_without_the_document_or_with_scripts_the_caller_may_read_is_written`), `crates/engine/src/tests/package.rs` (`a_confined_package_refuses_a_linked_javascript_file_outside_the_read_root`), `crates/ui-egui/src/tests/automation.rs` (`control_native_export_refuses_a_linked_javascript_file_outside_the_read_root`).
|
||||
- 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`).
|
||||
- Preserve Editing SVG under `--automation-read-root`: the native document an SVG or SVGZ carries leaves out an Export for Screens folder outside the read roots, and keeps the other export settings and the art; the open document keeps the folder, and a folder inside the roots is kept. `crates/engine/src/tests/links.rs` (`confined_preserve_editing_svg_leaves_out_an_export_folder_outside_the_read_roots`).
|
||||
|
||||
Reference in New Issue
Block a user