Scripts: Documents.add takes the artboard spacing file.new takes

artboardSpacing is refused above 100,000 points, the limit file.new
applies, so a value file.new would refuse throws a RangeError that names
artboardSpacing.
This commit is contained in:
dotCooCoo
2026-11-21 11:40:55 -08:00
parent 4b97cc8492
commit 4bc1f7a187
3 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -561,7 +561,7 @@ pub(crate) fn side_error(cmd: &str, units: Unit) -> crate::EngineError {
bad(cmd, format!("width and height must be more than 0 and at most {limit}"))
}
/// Largest artboard spacing, points.
const MAX_SPACING: f64 = 1.0e5;
pub(crate) const MAX_SPACING: f64 = 1.0e5;
pub fn color_mode_id(m: ColorMode) -> &'static str {
match m {
+2 -2
View File
@@ -763,8 +763,8 @@ impl NewDoc<'_> {
}
if let Some(d) = self.spacing {
let v = number(d, "artboardSpacing")?;
if !(0.0..=MAX_SIZE).contains(&v) {
return Err(HostError::Range("artboardSpacing must be from 0 to 3999856 points".into()));
if !(0.0..=crate::cmd::newdoc::MAX_SPACING).contains(&v) {
return Err(HostError::Range("artboardSpacing must be from 0 to 100000 points".into()));
}
layout.insert("spacing".into(), json!(v));
}
+3
View File
@@ -62,6 +62,9 @@ fn app_documents_track_active_tab_and_new_document() {
assert!(failure(&mut s, "app.documents.add(DocumentColorSpace.RGB, -5);").contains("width"));
assert!(failure(&mut s, "app.documents.add('RGB');").contains("colorSpace"));
assert!(failure(&mut s, "app.documents.add(undefined, 10, 10, 101);").contains("numArtBoards"));
// The spacing is refused at file.new's limit, with the script's own name for it.
let spacing = "app.documents.add(undefined, 10, 10, 2, DocumentArtboardLayout.Row, 100001);";
assert!(failure(&mut s, spacing).contains("artboardSpacing must be from 0 to 100000 points"));
assert!(failure(&mut s, "app.documents.index('none');").contains("Not found"));
assert_eq!(s.documents().len(), 3);
}