MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / safe_relative_path

Function safe_relative_path

packages/server/src/static_files/mod.rs:96–111  ·  view source on GitHub ↗
(path: &str)

Source from the content-addressed store, hash-verified

94}
95
96fn safe_relative_path(path: &str) -> Option<PathBuf> {
97 let trimmed = path.trim_start_matches('/');
98 if trimmed.is_empty() {
99 return Some(PathBuf::from("index.html"));
100 }
101
102 let mut relative = PathBuf::new();
103 for component in Path::new(trimmed).components() {
104 match component {
105 Component::Normal(part) => relative.push(part),
106 Component::CurDir => {}
107 Component::ParentDir | Component::RootDir | Component::Prefix(_) => return None,
108 }
109 }
110 Some(relative)
111}
112
113fn content_type_for_path(path: &Path) -> &'static str {
114 match path.extension().and_then(|extension| extension.to_str()) {

Callers 1

serve_static_innerFunction · 0.85

Calls 1

is_emptyMethod · 0.80

Tested by

no test coverage detected