Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Text: reject malformed explicit Story Options targets

skylar taylor-barrick3bacb1b02251
diff --git a/ROADMAP.md b/ROADMAP.md
index b517f64e9..2ef1d7e22 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -374,6 +374,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-24** · Story Options rejects malformed or nonexistent explicit story/frame IDs without changing the selected story, including an invalid frame alongside a valid story. Null targets remain absent; omitted targets still use the selection. No readiness percentage change.
- **2026-10-24** · Renaming a paragraph or character style, or moving it into a style group, keeps its Export Tagging under the new name, and undo puts it back under the old one. Deleting a tagged style drops its tagging and leaves the replacement style's own tagging as it was. No readiness percentage change.
- **2026-10-24** · Quick Apply and the application bar's search leave out the interface commands that failed or reset a setting when chosen there: those that need a workspace, a command and shortcut, a menu item, a panel, a window edge, an app page, a recent file or a swatch they can't give them, a Contextual Task Bar place, and Interface Color Theme, UI Scaling, Reset Shortcuts, the flattener preset, Screen Mode and Zoom To, which without a value switched to the dark theme, set 100%, cleared every custom shortcut or the preset, or went to Normal mode or 100% zoom. Each stays in the menu, panel or dialog that gives it the value. No readiness percentage change.
- **2026-10-24** · EPUB Export Options › Split Document, a dialog before File › Export EPUB… saves (`document.epubSplit`, stored with the document): off, a single paragraph style, or based on paragraph style export tags, with Paragraph Style Options › Export Tagging's Split Document flag marking those styles. A reflowable EPUB is one content file unless Split Document is on; the split before each top-level h1 from #791 is gone. A split before a list item or preformatted line no longer leaves an unclosed list or block in a content file. IDML import and export keep the setting and the flag, and Load Styles the flag. No readiness percentage change.
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index 43038f76a..a353cd1f5 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -1033,7 +1033,24 @@ fn story_options(s: &mut Session, p: &Value) -> Result<Value> {
if on.is_none() && size.is_none() {
return Err(bad(CMD, "nothing to set: give opticalMargin or opticalMarginSize"));
}
- let stories = if p.get("story").is_some() || p.get("frame").is_some() {
+ let explicit = |key| p.get(key).filter(|v| !v.is_null());
+ let stories = if explicit("story").is_some() || explicit("frame").is_some() {
+ // Explicit targets must not silently fall back to the current selection.
+ let doc = &s.doc()?.doc;
+ for key in ["story", "frame"] {
+ if let Some(value) = explicit(key) {
+ let id = value.as_u64().ok_or_else(|| bad(CMD, format!("`{key}` must be an unsigned integer")))?;
+ let sid = if key == "story" {
+ StoryId(id)
+ } else {
+ let item = doc.item(ItemId(id)).ok_or_else(|| bad(CMD, format!("no such frame {id}")))?;
+ item.text_frame().ok_or_else(|| bad(CMD, format!("frame {id} holds no text")))?.story
+ };
+ if doc.story(sid).is_none() {
+ return Err(bad(CMD, format!("no such story {}", sid.0)));
+ }
+ }
+ }
vec![story_of(s, p).ok_or_else(|| bad(CMD, "no such story"))?]
} else {
selected_stories(s)?
@@ -3359,6 +3376,68 @@ mod bidi_caret_tests {
mod story_options_tests {
use super::*;
+ #[test]
+ fn malformed_explicit_story_targets_do_not_change_the_selection() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 200], "content": "text", "text": "Selected"})).unwrap();
+ let sid = StoryId(r["story"].as_u64().unwrap());
+ for target in ["story", "frame"] {
+ for invalid in [json!("invalid"), json!(-1), json!(1.5), json!(true), json!({}), json!([]), json!(999_999)] {
+ let mut params = json!({"opticalMargin": true});
+ params[target] = invalid;
+ assert!(s.execute("story.options", &params).is_err(), "{params}");
+ assert!(!story(&s, sid).on, "{params} changed the selected story");
+ }
+ }
+ // Selection fallback still works when neither explicit target is supplied.
+ s.execute("story.options", &json!({"opticalMargin": true})).unwrap();
+ assert!(story(&s, sid).on);
+ s.execute("story.options", &json!({"frame": r["id"], "opticalMargin": false})).unwrap();
+ assert!(!story(&s, sid).on);
+ }
+
+ #[test]
+ fn story_options_treat_null_targets_as_absent_and_validate_both_explicit_ids() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [0, 0, 300, 200], "content": "text", "text": "Explicit"})).unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [0, 300, 300, 500], "content": "text", "text": "Selected"})).unwrap();
+ let aid = StoryId(a["story"].as_u64().unwrap());
+ let bid = StoryId(b["story"].as_u64().unwrap());
+ for targets in [json!({"story": null}), json!({"frame": null}), json!({"story": null, "frame": null})] {
+ let mut p = targets;
+ p["opticalMargin"] = json!(true);
+ s.execute("story.options", &p).unwrap();
+ assert!(story(&s, bid).on);
+ assert!(!story(&s, aid).on);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!(!story(&s, bid).on);
+ }
+ for targets in [json!({"story": null, "frame": a["id"]}), json!({"story": a["story"], "frame": null})] {
+ let mut p = targets;
+ p["opticalMargin"] = json!(true);
+ s.execute("story.options", &p).unwrap();
+ assert!(story(&s, aid).on);
+ assert!(!story(&s, bid).on);
+ s.execute("edit.undo", &json!({})).unwrap();
+ }
+ // Even a frame ignored by story precedence must be valid when explicitly supplied.
+ let non_text = s.execute("frame.create", &json!({"rect": [400, 0, 500, 100]})).unwrap();
+ for (targets, message) in [
+ (json!({"frame": 999_999}), "no such frame 999999".to_string()),
+ (json!({"frame": non_text["id"]}), format!("frame {} holds no text", non_text["id"])),
+ (json!({"story": 999_999}), "no such story 999999".to_string()),
+ (json!({"story": a["story"], "frame": 999_999}), "no such frame 999999".to_string()),
+ ] {
+ let mut p = targets;
+ p["opticalMargin"] = json!(true);
+ assert!(s.execute("story.options", &p).unwrap_err().to_string().contains(&message), "{p}: expected {message}");
+ assert!(!story(&s, aid).on);
+ assert!(!story(&s, bid).on);
+ }
+ }
+
fn first_x(s: &Session, sid: StoryId) -> f64 {
let cs = s.cache.get(&s.doc().unwrap().doc, sid, None);
cs.frames[0].lines[0].glyphs[0].x