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())); } }, }