mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Save for Web: refuse slice numbers with a whole-image path and a null slices (CodeRabbit review on crates/engine/src/cmd/web_cmds/save_web.rs:211)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
f1427bba65
commit
1fd0ec7a61
2 files changed
+3
-1
No files matched your search
@@ -208,7 +208,7 @@ fn slice_pick(p: &Value, cmd: &str, doc: &photocraft_doc::Document) -> Result<Sl
|
||||
// `path` alone is the whole image in one file (with `slices` too, the slices go next to it):
|
||||
// the chosen slices would be ignored, so a document with slices refuses it.
|
||||
let given = |k: &str| p.get(k).and_then(Value::as_str).is_some_and(|v| !v.is_empty());
|
||||
if given("path") && !given("dir") && p.get("slices").is_none() && count > 1 {
|
||||
if given("path") && !given("dir") && matches!(p.get("slices"), None | Some(Value::Null)) && count > 1 {
|
||||
return Err(bad(cmd, "`path` writes the whole image as one file: to export the slices in `numbers`, use `dir`"));
|
||||
}
|
||||
// `folder` alone (#5305) is the whole image too, under the document's name.
|
||||
|
||||
@@ -1560,6 +1560,8 @@ fn a_whole_image_path_with_slice_numbers_is_refused() {
|
||||
assert_refused(&mut s, &dir, json!({"format": "png24", "path": path, "dir": "", "numbers": [left, right]}), "use `dir`");
|
||||
// `folder` alone is the whole image under the document's name (#5305): refused the same way.
|
||||
assert_refused(&mut s, &dir, json!({"format": "png24", "folder": dir, "numbers": [right]}), "use `dir`");
|
||||
// An explicit null `slices` is the default mode, as if absent.
|
||||
assert_refused(&mut s, &dir, json!({"format": "png24", "path": path, "slices": null, "numbers": [right]}), "use `dir`");
|
||||
// Valid calls still work: `path` alone is the whole image; with `slices`, the chosen slices
|
||||
// go next to it; `dir` with `numbers` writes those slices.
|
||||
let r = s.execute("file.export.saveForWebLegacy", json!({"format": "png24", "path": path})).unwrap();
|
||||
|
||||
Reference in new issue
Block a user