fixing code validation, and also added rename instance
This commit is contained in:
15
src/util.rs
Normal file
15
src/util.rs
Normal 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(_)))
|
||||
}
|
||||
Reference in New Issue
Block a user