Skip to content

Commit

Permalink
Convert special characters to hex values in package version
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Piotrowski <[email protected]>
  • Loading branch information
Ruadhri17 committed Feb 6, 2024
1 parent 0f35e21 commit 6df6469
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/core/plugin_sm/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,17 @@ fn sm_path(name: &str, version: &Option<String>, target_dir_path: impl AsRef<Pat
filename.push_str(version.as_str());
}

target_dir_path.as_ref().join(filename)
target_dir_path.as_ref().join(sanitize_filename(&filename))
}

fn sanitize_filename(filename: &str) -> String {
let mut result = String::new();
filename.chars().for_each(|c| {
if matches!(c as u8, b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'-' | b'.' | b'_' | b'~') {
result.push(c)
} else {
result.push_str(&format!("%{:x?}", c as u8))
}
});
result
}

0 comments on commit 6df6469

Please sign in to comment.