Plot: an unknown extension needs a real format selector (review on #2585)

device None and a null or unknown output no longer bypass the refusal
and write a PDF under the odd name; only a recognised output or a
device that resolves does. Test: plot_path_extension_picks_the_format_like_export.
This commit is contained in:
SBaksa
2026-11-01 22:20:10 +11:00
parent 0e871873e7
commit d6555e5bdf
2 changed files with 12 additions and 2 deletions
+10
View File
@@ -340,6 +340,16 @@ fn plot_path_extension_picks_the_format_like_export() {
assert!(!dir.join("noext").exists());
let e = s.execute("plot", &json!({"path": path("y.png"), "device": "CADCraft PDF"})).unwrap_err().to_string();
assert!(e.contains("writes pdf") && e.contains("png"), "{e}");
// A device that resolves to none, or a null/unknown `output`, names no format: the refusal stands.
for p in [
json!({"path": path("x.txt"), "device": "None"}),
json!({"path": path("x.txt"), "output": null}),
json!({"path": path("x.txt"), "output": "bogus"}),
] {
let e = s.execute("plot", &p).unwrap_err().to_string();
assert!(e.contains("png") && e.contains("svg") && e.contains("pdf"), "{e}");
assert!(!dir.join("x.txt").exists(), "nothing written under an unknown extension");
}
// An explicit output still decides for an odd name.
assert_eq!(s.execute("plot", &json!({"path": path("z.txt"), "output": "pdf"})).unwrap()["format"], "pdf");
std::fs::remove_dir_all(&dir).ok();
+2 -2
View File
@@ -300,8 +300,8 @@ pub(crate) fn plot_options(s: &Session, p: &Value, cmd: &str) -> Result<Value> {
// refuse it, as EXPORT does, unless `output` or a device says what to write.
if cmd == "plot"
&& by_path.is_none()
&& p.get("output").is_none()
&& !given.is_some_and(|n| !n.is_empty())
&& !p.get("output").and_then(Value::as_str).is_some_and(|o| PlotOutput::parse(o).is_some())
&& !(dev.is_some() && given.is_some_and(|n| !n.is_empty()))
&& let Some(path) = str_param(p, "path")
{
return Err(bad(