Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- fix: sanitize characters in path #66

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{
path::{self, PathBuf},
};

use super::execution_context::ExecutionContext;
use super::path_buf_ext::PathBufExt;
use super::{execution_context::ExecutionContext, file_name_utils::sanitize_for_file_name};
use nanoid::nanoid;

#[derive(Default, Clone)]
Expand All @@ -26,14 +26,20 @@ pub struct DenoExecutionStorage {
impl DenoExecutionStorage {
pub fn new(context: ExecutionContext) -> Self {
let code_id = format!("{}-{}", context.code_id, nanoid!());
let root =
path::absolute(context.storage.join(context.context_id.clone()).clone()).unwrap();
let root = path::absolute(
context
.storage
.join(sanitize_for_file_name(context.context_id.clone()))
.clone(),
)
.unwrap();
let root_code = path::absolute(root.join("code")).unwrap();
let code = path::absolute(root_code.join(code_id.clone())).unwrap();
let logs = path::absolute(root.join("logs")).unwrap();
let log_file = path::absolute(logs.join(format!(
"log_{}_{}.log",
context.context_id, context.execution_id,
sanitize_for_file_name(context.context_id.clone()),
sanitize_for_file_name(context.execution_id.clone())
)))
.unwrap();
let deno_cache = path::absolute(root.join("deno-cache")).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions libs/shinkai-tools-runner/src/tools/file_name_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

pub fn sanitize_for_file_name(file_name: String) -> String {
file_name.replace(|c: char| !c.is_alphanumeric() && c != '-' && c != '_', "")
}
3 changes: 2 additions & 1 deletion libs/shinkai-tools-runner/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod execution_error;
pub mod run_result;
pub mod tool;
pub mod tool_definition;
mod path_buf_ext;
mod path_buf_ext;
mod file_name_utils;
Loading