From 08f1d8cedbb7883d40ecc8ca94c3bde268110f89 Mon Sep 17 00:00:00 2001 From: Roman Kolesnikov Date: Tue, 25 Feb 2025 18:36:47 +0100 Subject: [PATCH 1/2] fix detecting windows root paths --- src/line.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/line.rs b/src/line.rs index 39d31a8..22f5e05 100644 --- a/src/line.rs +++ b/src/line.rs @@ -310,5 +310,5 @@ fn has_unix_root(p: &str) -> bool { /// Check if the path in the given string has a windows style root fn has_windows_root(p: &str) -> bool { - p.starts_with('\\') || p.get(1..3) == Some(":\\") + p.starts_with('\\') || p.get(1..3) == Some(":\\") || p.get(1..3) == Some(":/") } From babee61204337055438425128e83fca7aaa6d8f6 Mon Sep 17 00:00:00 2001 From: Roman Kolesnikov Date: Thu, 20 Mar 2025 10:55:01 +0100 Subject: [PATCH 2/2] refactor --- src/line.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/line.rs b/src/line.rs index 22f5e05..40be3dd 100644 --- a/src/line.rs +++ b/src/line.rs @@ -287,10 +287,10 @@ fn render_file( } fn path_push(path: &mut String, p: &str) { - if has_unix_root(p) || has_windows_root(p) { + if has_forward_slash_root(p) || has_backward_slash_root(p) { *path = p.to_string(); } else { - let dir_separator = if has_windows_root(path.as_str()) { + let dir_separator = if has_backward_slash_root(path.as_str()) { '\\' } else { '/' @@ -304,11 +304,11 @@ fn path_push(path: &mut String, p: &str) { } /// Check if the path in the given string has a unix style root -fn has_unix_root(p: &str) -> bool { - p.starts_with('/') +fn has_forward_slash_root(p: &str) -> bool { + p.starts_with('/') || p.get(1..3) == Some(":/") } /// Check if the path in the given string has a windows style root -fn has_windows_root(p: &str) -> bool { - p.starts_with('\\') || p.get(1..3) == Some(":\\") || p.get(1..3) == Some(":/") +fn has_backward_slash_root(p: &str) -> bool { + p.starts_with('\\') || p.get(1..3) == Some(":\\") }