From c5b5bcd69c8e2c7fd551f9de8389b9fc77ba8b66 Mon Sep 17 00:00:00 2001 From: Henk Oordt Date: Mon, 4 Nov 2024 15:54:18 +0100 Subject: [PATCH 1/2] Panic in case rewriting dependency paths as relative yields a non-UTF8 sequence --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aa9faef..865c8a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,8 +82,11 @@ fn rewrite_dep_path_as_relative>(dep: &mut Dependency, if let Dependency::Detailed(detail) = dep { detail.path = detail.path.as_mut().map(|path| { pathdiff::diff_paths(path, parent.as_ref()) - .unwrap() - .to_string_lossy() + .expect( + "Error rewriting dependency path as relative: unable to determine path diff.", + ) + .to_str() + .expect("Error rewriting dependency path as relative: path diff is not UTF-8.") .to_string() }) } From 4287c0ec718caa7caba3e59ca9e9b0297f43ea0e Mon Sep 17 00:00:00 2001 From: Henk Oordt Date: Tue, 5 Nov 2024 13:53:10 +0100 Subject: [PATCH 2/2] Panic in case rewriting dependency paths as absoluteyields a non-UTF8 sequence --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 865c8a5..b4a6b89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,8 @@ fn rewrite_dep_paths_as_absolute<'a, P: AsRef>( .join(path) .canonicalize() .unwrap() - .to_string_lossy() + .to_str() + .expect("Canonicalized absolute path contained non-UTF-8 segments.") .to_string() }) } @@ -81,7 +82,7 @@ fn rewrite_dep_paths_as_absolute<'a, P: AsRef>( fn rewrite_dep_path_as_relative>(dep: &mut Dependency, parent: P) { if let Dependency::Detailed(detail) = dep { detail.path = detail.path.as_mut().map(|path| { - pathdiff::diff_paths(path, parent.as_ref()) + pathdiff::diff_paths(path, parent.as_ref().canonicalize().unwrap()) .expect( "Error rewriting dependency path as relative: unable to determine path diff.", )