mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-01 05:57:09 -06:00
Merge PR #3006: CLI-HOSTILE: render --set refuses inf / NaN instead of dropping the value
This commit is contained in:
@@ -685,7 +685,9 @@ fn render(args: &[String]) -> Result<(), String> {
|
||||
"--set" => {
|
||||
let kv = take_value(args, &mut i, "--set")?;
|
||||
let (k, v) = kv.split_once('=').ok_or_else(|| format!("--set expects control=value, got `{kv}`"))?;
|
||||
let v: f64 = v.trim().parse().map_err(|_| format!("--set {k}: `{v}` is not a number"))?;
|
||||
// `inf` / `NaN` parse as f64 but become JSON null, which the control would silently ignore.
|
||||
let v: f64 =
|
||||
v.trim().parse().ok().filter(|n: &f64| n.is_finite()).ok_or_else(|| format!("--set {k}: `{v}` is not a finite number"))?;
|
||||
values.insert(k.trim().to_string(), json!(v));
|
||||
}
|
||||
"--settings" => settings = Some(read_settings(take_value(args, &mut i, "--settings")?)?),
|
||||
|
||||
@@ -184,6 +184,12 @@ fn render_subcommand() {
|
||||
let o = Command::new(binary()).args(["render", input.to_str().unwrap(), "-o", out.to_str().unwrap(), "--set", "nope=1"]).output().unwrap();
|
||||
assert!(!o.status.success());
|
||||
assert!(String::from_utf8_lossy(&o.stderr).contains("unknown control"));
|
||||
// Values that parse as f64 but are not finite fail cleanly too.
|
||||
for bad in ["light.exposure=inf", "light.exposure=-inf", "light.exposure=NaN", "light.exposure=1e999"] {
|
||||
let o = Command::new(BIN).args(["render", input.to_str().unwrap(), "-o", out.to_str().unwrap(), "--set", bad]).output().unwrap();
|
||||
assert!(!o.status.success(), "{bad} must be refused");
|
||||
assert!(String::from_utf8_lossy(&o.stderr).contains("not a finite number"), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Issue #1730: `render --settings` took a `.lcpreset` from `preset.export`, ignored its wrapper
|
||||
|
||||
Reference in New Issue
Block a user