MCPcopy Create free account
hub / github.com/AI45Lab/Code / validate_relative_pattern

Function validate_relative_pattern

core/src/workspace/mod.rs:929–944  ·  view source on GitHub ↗
(pattern: &str, label: &str)

Source from the content-addressed store, hash-verified

927}
928
929pub(crate) fn validate_relative_pattern(pattern: &str, label: &str) -> Result<()> {
930 let pattern = pattern.trim();
931 if pattern.is_empty() {
932 bail!("{label} cannot be empty");
933 }
934 if has_windows_path_prefix(pattern) || Path::new(pattern).is_absolute() {
935 bail!("{label} must be relative to the workspace");
936 }
937
938 let normalized = pattern.replace('\\', "/");
939 if normalized.split('/').any(|component| component == "..") {
940 bail!("{label} must not contain parent directory traversal");
941 }
942
943 Ok(())
944}
945
946fn normalize_relative_path(path: &Path) -> Result<PathBuf> {
947 let mut out = PathBuf::new();

Callers 5

globMethod · 0.85
grepMethod · 0.85
globMethod · 0.85
grepMethod · 0.85
load_toolsFunction · 0.85

Calls 2

has_windows_path_prefixFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected