From 883357a7ddeafb7ac1dd31312de0e85b55a3dd66 Mon Sep 17 00:00:00 2001 From: Johan Sigfrids Date: Sun, 5 Aug 2018 08:59:56 +0300 Subject: [PATCH] Handle relative path case --- src/cmd/serve.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 3cf5f970..2406de04 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -322,7 +322,7 @@ fn is_temp_file(path: &Path) -> bool { /// to be reloaded fn detect_change_kind(pwd: &Path, path: &Path) -> (ChangeKind, PathBuf) { let mut partial_path = PathBuf::from("/"); - partial_path.push(path.strip_prefix(pwd).unwrap()); + partial_path.push(path.strip_prefix(pwd).unwrap_or(path)); let change_kind = if partial_path.starts_with("/templates") { ChangeKind::Templates @@ -396,7 +396,6 @@ mod tests { } } - #[test] #[cfg(windows)] fn windows_path_handling() { @@ -406,4 +405,11 @@ mod tests { assert_eq!(expected, detect_change_kind(pwd, path)); } + #[test] + fn relative_path() { + let expected = (ChangeKind::Templates, PathBuf::from("/templates/hello.html")); + let pwd = Path::new("/home/johan/site"); + let path = Path::new("templates/hello.html"); + assert_eq!(expected, detect_change_kind(pwd, path)); + } }