mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-10 20:40:30 -06:00
Plot: refuse a path whose extension names no format (review on #2585)
A path like x.txt (or one with no extension) wrote a PDF under that name. Like EXPORT, PLOT now refuses it unless output or a device says what to write. Test: plot_path_extension_picks_the_format_like_export.
This commit is contained in:
@@ -36,11 +36,12 @@ fn the_extension_picks_png_svg_or_pdf() {
|
||||
assert_eq!(r["format"], format, "{name}: the reply names the format");
|
||||
assert_eq!(magic(&out), head, "{name}: the file holds that format");
|
||||
}
|
||||
// No path, or an extension that names no format: PDF as before.
|
||||
// No path: PDF data as before. An extension that names no format is refused, like EXPORT.
|
||||
assert_eq!(s.execute("plot", &json!({ "layout": "Model" })).unwrap()["format"], "pdf");
|
||||
let other = dir.join("e.plt");
|
||||
assert_eq!(s.execute("plot", &json!({ "path": other.to_string_lossy(), "layout": "Model" })).unwrap()["format"], "pdf");
|
||||
assert_eq!(magic(&other), b"%PDF-");
|
||||
let e = s.execute("plot", &json!({ "path": other.to_string_lossy(), "layout": "Model" })).unwrap_err().to_string();
|
||||
assert!(e.contains("png") && e.contains("svg") && e.contains("pdf"), "{e}");
|
||||
assert!(!other.exists(), "nothing is written under a name that is not a format");
|
||||
// EXPORTPDF always writes PDF.
|
||||
let pdf = dir.join("f.png");
|
||||
s.execute("exportpdf", &json!({ "path": pdf.to_string_lossy(), "layout": "Model" })).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user