Skip to content

Commit

Permalink
Add absolute filepath support (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurikini authored Oct 29, 2024
1 parent ec9c68b commit 89b00d3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ enum RequestType {
}

pub fn convert_file_path(filename: &str) -> PathBuf {
let formatted_filename = filename.trim_start_matches(|c| c == '/' || c == '\\').to_string();
let normalized_filename = if MAIN_SEPARATOR == '\\' {
filename.replace('/', "\\")
formatted_filename.replace('/', "\\")
} else {
filename.replace('\\', "/")
formatted_filename.replace('\\', "/")
};

PathBuf::from(normalized_filename)
Expand Down Expand Up @@ -401,6 +402,16 @@ mod tests {
correct_path.push("test.file");
assert_eq!(path, correct_path);

let path = convert_file_path("\\test.file");
let mut correct_path = PathBuf::new();
correct_path.push("test.file");
assert_eq!(path, correct_path);

let path = convert_file_path("/test.file");
let mut correct_path = PathBuf::new();
correct_path.push("test.file");
assert_eq!(path, correct_path);

let path = convert_file_path("test\\test.file");
let mut correct_path = PathBuf::new();
correct_path.push("test");
Expand Down

0 comments on commit 89b00d3

Please sign in to comment.