validate filename

This commit is contained in:
postscriptum 2025-07-05 10:33:00 +03:00
parent e60c8cf724
commit afd71fa435

View file

@ -11,7 +11,7 @@ use source::Source;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
fs, fs,
path::PathBuf, path::{MAIN_SEPARATOR, PathBuf},
str::FromStr, str::FromStr,
}; };
use template::Template; use template::Template;
@ -35,6 +35,13 @@ impl Nex {
(is_cleanup, is_debug): (bool, bool), (is_cleanup, is_debug): (bool, bool),
user_names: &Vec<String>, user_names: &Vec<String>,
) -> Result<Self> { ) -> Result<Self> {
// validate filename
if filename
.trim_matches(MAIN_SEPARATOR)
.contains(MAIN_SEPARATOR)
{
bail!("File name should not contain subdir `{MAIN_SEPARATOR}` separator!")
}
// init data export location // init data export location
let target = PathBuf::from_str(&target_dir)?.canonicalize()?; let target = PathBuf::from_str(&target_dir)?.canonicalize()?;
if !target.is_dir() { if !target.is_dir() {