Refuse a Selective Color channel the command would refuse

The scalar form's channels went through `jnum`, which returns `None` for
anything that is not a number, so `{"colors": "reds", "cyan": "35"}` exported as
an untouched range while the command errors on it
(`adjust_cmds::selective_from_params` → `percent`). The export would have
written an adjustment that is not the one recorded.

A channel that is present and not null must now be a finite number, or the step
cannot be written and takes the refusal path. `null` counts as absent, as the
command's `given` reads it.
This commit is contained in:
Hamza committed 2026-10-19 18:29:33 +05:00
1 parent 7835d05a54
commit f309665694
2 files changed
+18 -2

No files matched your search

+7 -2
View File
@@ -740,8 +740,13 @@ fn selective_to(p: &Value) -> Option<Descriptor> {
let row = rows.get_mut(i)?;
let mut v = row.unwrap_or([0.0; 4]);
for (slot, key) in v.iter_mut().zip(["cyan", "magenta", "yellow", "black"]) {
if let Some(n) = jnum(p, key) {
*slot = n;
// A channel that is given but is not a number is an error in the command
// (`adjust_cmds::selective_from_params`), so a step carrying one cannot be written
// either: ignoring it would export a different adjustment than the one recorded.
// `null` counts as absent there, and so here.
match p.get(key) {
None | Some(Value::Null) => {}
Some(_) => *slot = jnum(p, key)?,
}
}
*row = Some(v);
+11
View File
@@ -197,6 +197,17 @@ fn a_selective_color_step_in_the_scalar_form_keeps_its_values() {
// The array form is unchanged.
let array = back(json!({"method": "relative", "yellows": [0, 0, -15, 5]}));
assert_eq!(range(&array, "yellows"), [0.0, 0.0, -15.0, 5.0], "{array}");
// A channel the command would refuse is not quietly dropped: the step is refused too, since
// writing it would export an adjustment that is not the one recorded. `null` is absent, as
// the command reads it.
let mut s = Session::new();
s.actions.list.push(Action::new("A", vec![("image.adjustments.selectiveColor".into(), json!({"colors": "reds", "cyan": "35"}))]));
let e = s.execute("actions.save", json!({"action": "A"})).unwrap_err().to_string();
assert!(e.contains("image.adjustments.selectiveColor"), "{e}");
let nulled = back(json!({"colors": "reds", "cyan": 35, "magenta": null}));
assert_eq!(range(&nulled, "reds"), [35.0, 0.0, 0.0, 0.0], "{nulled}");
}
#[test]