Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(atn): don't read an odd Save As format as a plain Save

Jason White81b917a6b895
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rs
index bb1cfe075..66cc99a71 100644
--- a/crates/engine/src/atn_cmds.rs
+++ b/crates/engine/src/atn_cmds.rs
@@ -1576,10 +1576,16 @@ fn path_extension(path: &str) -> Option<String> {
/// before writing rather than saving over the played file (#7102).
fn save_from(d: &Descriptor) -> Mapped {
let unsupported = Mapped::Unsupported { harmless: false };
- let (format, dest) = (get_obj(d, "As "), d.get("In "));
- if format.is_none() && dest.is_none() {
- return step("file.save", json!({}));
- }
+ let dest = d.get("In ");
+ let format = match d.get("As ") {
+ None if dest.is_none() => return step("file.save", json!({})),
+ None => None,
+ // A format that isn't a descriptor can't be checked against the destination.
+ Some(_) => match get_obj(d, "As ") {
+ Some(f) => Some(f),
+ None => return unsupported,
+ },
+ };
let Some(path) = dest.and_then(path_text) else { return unsupported };
if get_bool(d, "DIDr") == Some(true) {
return unsupported;
diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rs
index 3148dadc6..ff42da5e3 100644
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@ -1452,10 +1452,13 @@ fn save_as_that_cannot_be_mapped_stops_playback_instead_of_saving_over_the_file(
item("save", "Save", Some(save_as("PNGF", "/out/result.webp"))),
item("save", "Save", Some(save_as("GIFf", "/out/result.gif"))),
item("save", "Save", Some(desc("null").with("As ", D::Descriptor(desc("PNGF"))))),
+ // A format that isn't a descriptor, with and without a destination.
+ item("save", "Save", Some(desc("null").with("As ", long(1.0)))),
+ item("save", "Save", Some(desc("null").with("As ", long(1.0)).with("In ", path_value("/out/result.png")))),
]);
let imp = import(&atn::write(&file).unwrap()).unwrap();
let ids: Vec<&str> = imp.actions[0].steps.iter().map(|(id, _)| id.as_str()).collect();
- assert_eq!(ids, [PHOTOSHOP_STEP; 5]);
+ assert_eq!(ids, [PHOTOSHOP_STEP; 7]);
assert!(imp.actions[0].disabled.is_empty(), "kept saves stay on, so playback stops on them");
// The kept steps are written back byte for byte.
let a = &imp.actions[0];