mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 13:47:21 -06:00
Libraries: library loads check name before reading the file
swatch.library.load, graphicStyle.loadLibrary, symbol.loadLibrary and brush.loadLibrary read the whole file or decoded data before checking `name`, so a call with a `name` that is not a string read the file first, and with a missing file reported the file error instead of the parameter error. The shared loader now checks every parameter before it reads anything.
This commit is contained in:
@@ -215,6 +215,22 @@ fn library_commands_refuse_params_of_the_wrong_form() {
|
||||
assert!(r["added"].as_array().is_some_and(|a| !a.is_empty()), "{r}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_loads_validate_name_before_reading_a_file_or_decoding_data() {
|
||||
let mut s = session();
|
||||
let missing = temp_dir("invalid-load-name").join("missing.vcswatches").to_string_lossy().to_string();
|
||||
for cmd in ["swatch.library.load", "graphicStyle.loadLibrary", "symbol.loadLibrary", "brush.loadLibrary"] {
|
||||
for name in [json!(5), json!([])] {
|
||||
let p = json!({"path": missing, "name": name});
|
||||
let e = s.execute(cmd, &p).unwrap_err().to_string();
|
||||
assert!(e.contains("`name` must be a string"), "{cmd} {p}: {e}");
|
||||
}
|
||||
let p = json!({"dataBase64": "not base64!", "name": 5});
|
||||
let e = s.execute(cmd, &p).unwrap_err().to_string();
|
||||
assert!(e.contains("`name` must be a string"), "{cmd} {p}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn libraries_saved_in_the_user_folder_are_user_defined() {
|
||||
let dir = temp_dir("user");
|
||||
|
||||
Reference in New Issue
Block a user