mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
File Info: a template name that is not a file name is refused
file.info.applyTemplate with a name such as a/b no longer opens the template its safe file name names (a-b.xmp): a name that matches no listed template and is not a file name as it is gives an error. docs/mcp.md cites the help page that describes metadata templates.
This commit is contained in:
@@ -257,6 +257,9 @@ fn template_bytes(s: &Session, p: &Value) -> Result<Vec<u8>> {
|
||||
.min_by_key(|f| (f != name, *f != own));
|
||||
if let Some(file) = listed {
|
||||
path = dir.join(file).to_string_lossy().into_owned();
|
||||
} else if std::path::Path::new(&path).file_stem().map(|s| s.to_string_lossy()).as_deref() != Some(name) {
|
||||
// A name that is not a file name as it is never opens another template.
|
||||
return Err(bad(APPLY, "the template name isn't usable as a file name"));
|
||||
}
|
||||
let plain_file = |path: &str| std::fs::symlink_metadata(path).is_ok_and(|m| m.is_file());
|
||||
if std::fs::symlink_metadata(&path).is_ok() && !plain_file(&path) {
|
||||
|
||||
@@ -779,6 +779,15 @@ fn the_templates_folder_lists_only_xmp_files_and_can_be_made() {
|
||||
assert_eq!(r["author"], "Grace");
|
||||
let r = s.execute("file.info.applyTemplate", &json!({"name": "b.XMP.xmp", "mode": "replace", "apply": false})).unwrap();
|
||||
assert_eq!(r["author"], "Ada");
|
||||
// A name that is not a file name never opens the template its safe form names.
|
||||
let grace = vectorcraft_pdf::metadata_template(&vectorcraft_pdf::FileInfo { author: Some("Grace".into()), ..Default::default() });
|
||||
std::fs::write(folder.join("a-b.xmp"), grace).unwrap();
|
||||
let r = s.execute("file.info.applyTemplate", &json!({"name": "a-b", "mode": "replace", "apply": false})).unwrap();
|
||||
assert_eq!(r["author"], "Grace");
|
||||
for name in ["a/b", "a\\b", "a:b"] {
|
||||
let e = s.execute("file.info.applyTemplate", &json!({"name": name, "mode": "replace", "apply": false})).unwrap_err();
|
||||
assert!(e.to_string().contains("isn't usable as a file name"), "{name}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+1
-1
@@ -7608,7 +7608,7 @@ A PDF, `.ai` or `.ait` also opens with the `authorTitle` and `rating` its XMP pa
|
||||
`xmp:Rating`, a whole number from 0 to 5).
|
||||
|
||||
Metadata templates (the menu at the top of File Info: Save Metadata Template…, Import…, the saved templates and
|
||||
Templates Folder; https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260) keep File
|
||||
Templates Folder; https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=278) keep File
|
||||
Info fields in an XMP file. `file.info.saveTemplate {name?, path?, fields?}` writes the `title` (when it is not the
|
||||
document's name), `author`, `authorTitle`, `description`, `keywords`, `rating` (from 1), `copyrightStatus`,
|
||||
`copyrightNotice` and `copyrightUrl` that have a value as an XMP packet, using the properties listed above; the dates
|
||||
|
||||
Reference in New Issue
Block a user