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

Add absolute filepath support #30

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions src/server.rs
mayurikini marked this conversation as resolved.
Show resolved Hide resolved
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,13 +402,13 @@ mod tests {
correct_path.push("test.file");
assert_eq!(path, correct_path);

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

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