From 03ae57e2e145897aee02618dc69594c08096da21 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 6 Jan 2024 11:13:52 -0800 Subject: [PATCH] sanitize --- src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ec0a258..3fdfdaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,7 +264,7 @@ enum TrimStackInstruction{ enum WriteStackInstruction<'a>{ Node(&'a TreeNode), - PushFolder(std::path::Component<'a>), + PushFolder(String), PopFolder, Destroy(Ref), } @@ -280,8 +280,12 @@ impl PropertiesOverride{ } } +fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{ + lazy_regex::regex!(r"[^a-zA-Z0-9._-]").replace_all(s,"_") +} + fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeNode)->AResult<()>{ - file.push(node.name.as_str()); + file.push(sanitize(node.name.as_str()).as_ref()); match node.class{ Class::Folder=>(), Class::ModuleScript|Class::LocalScript|Class::Script=>{ @@ -429,7 +433,7 @@ fn decompile(input_file:std::path::PathBuf,output_folder:std::path::PathBuf)->AR if has_children||properties.is_some(){ //push temp subfolder let mut subfolder=folder.clone(); - subfolder.push(node.name.as_str()); + subfolder.push(sanitize(node.name.as_str()).as_ref()); //make folder std::fs::create_dir(subfolder.clone())?; //write properties @@ -457,7 +461,7 @@ fn decompile(input_file:std::path::PathBuf,output_folder:std::path::PathBuf)->AR stack.push(WriteStackInstruction::Node(c)); } } - stack.push(WriteStackInstruction::PushFolder(std::path::Component::Normal(std::ffi::OsStr::new(node.name.as_str())))); + stack.push(WriteStackInstruction::PushFolder(sanitize(node.name.as_str()).to_string())); } }, }