mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(xtask): reject device names in PSD recipe IDs
Reject reserved Windows device names case-insensitively before the runner creates output artifacts. Cover all reserved IDs and ordinary near matches through recipe schema validation. Fixes #15822.
This commit is contained in:
1 file changed
+28
-1
@@ -81,7 +81,13 @@ fn read_limited(path: &Path) -> Result<Vec<u8>, String> {
|
||||
|
||||
/// Accept a case identifier that can safely name one output subdirectory.
|
||||
fn valid_id(id: &str) -> bool {
|
||||
!id.is_empty() && id.len() <= 100 && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
|
||||
if id.is_empty() || id.len() > 100 || !id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_') {
|
||||
return false;
|
||||
}
|
||||
// These names resolve to devices on Windows, so the case cannot hold its output files.
|
||||
let name = id.to_ascii_uppercase();
|
||||
let port = name.strip_prefix("COM").or_else(|| name.strip_prefix("LPT")).is_some_and(|n| matches!(n.as_bytes(), [b'1'..=b'9']));
|
||||
!matches!(name.as_str(), "CON" | "PRN" | "AUX" | "NUL") && !port
|
||||
}
|
||||
|
||||
/// Reject unsupported recipes, unsafe paths, duplicate IDs, and incomplete checks.
|
||||
@@ -649,4 +655,25 @@ exit 1
|
||||
assert_eq!(verify(&[Check::ChangedTo { path: "/n".into(), value: json!(17) }], &json!({}), &after)[0]["status"], "pass");
|
||||
assert_eq!(verify(&[Check::Equals { path: "/m".into(), value: json!(1) }], &before, &after)[0]["status"], "fail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schema_rejects_windows_device_ids_but_allows_near_matches() {
|
||||
let recipe = json!({"version":1,"corpus_revision":"pin","cases":[{"id":"case","base":"x.psd","base_sha256":"a".repeat(64),
|
||||
"target":{"kind":"Text"},"checks":[{"op":"unchanged","path":"/name"}]}]});
|
||||
let mut recipes: Recipes = serde_json::from_value(recipe).unwrap();
|
||||
let mut reserved = vec!["CON".to_string(), "PRN".to_string(), "AUX".to_string(), "NUL".to_string()];
|
||||
for n in 1..=9 {
|
||||
reserved.extend([format!("COM{n}"), format!("LPT{n}")]);
|
||||
}
|
||||
for id in reserved {
|
||||
for variant in [id.clone(), id.to_ascii_lowercase(), format!("{}{}", &id[..1], id[1..].to_ascii_lowercase())] {
|
||||
recipes.cases[0].id = variant.clone();
|
||||
assert_eq!(validate(&recipes), Err(format!("invalid or duplicate case id: {variant}")), "{variant}");
|
||||
}
|
||||
}
|
||||
for id in ["console", "PRN-1", "auxiliary", "NUL_", "COM0", "COM10", "LPT0", "LPT10", "case-1"] {
|
||||
recipes.cases[0].id = id.to_string();
|
||||
assert!(validate(&recipes).is_ok(), "{id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user