fixing code validation, and also added rename instance

This commit is contained in:
2026-07-25 16:41:53 -04:00
parent fef78fabc8
commit 30d6749d8c
5 changed files with 65 additions and 11 deletions

15
src/util.rs Normal file
View File

@@ -0,0 +1,15 @@
use std::path::Path;
pub fn is_valid_name(name: &str) -> bool {
let mut components = Path::new(name).components();
matches!(
(components.next(), components.next()),
(Some(std::path::Component::Normal(_)), None)
)
}
pub fn is_safe_relative_path(path: &str) -> bool {
let p = Path::new(path);
!p.as_os_str().is_empty()
&& p.components()
.all(|c| matches!(c, std::path::Component::Normal(_)))
}