Skip to content

Commit

Permalink
Temporarily fix rust-lang/rust#89658
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Oct 11, 2021
1 parent 3a418e4 commit da9b7b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,27 @@ fn get_prefix(base: &BasePath) -> PrefixComponent<'_> {
}

fn push_separator(base: &mut BasePathBuf) {
// https://github.com/rust-lang/rust/issues/89658
/*
base.replace_with(|mut base| {
// Add a separator if necessary.
base.push("");
base
});
*/

const SEPARATOR: &str = "\\";

if let Some(Component::Prefix(prefix)) = base.components().next_back() {
if matches!(prefix.kind(), Prefix::Disk(_) | Prefix::VerbatimDisk(_)) {
return;
}
}
// This inefficient implementation must be used until the above issue is
// resolved.
if !base.0.to_string_lossy().ends_with(SEPARATOR) {
base.0.push(SEPARATOR);
}
}

pub(super) fn push(base: &mut BasePathBuf, initial_path: &Path) {
Expand Down
21 changes: 21 additions & 0 deletions tests/edge_cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mod common;

#[cfg(windows)]
#[test]
fn test_edge_cases() {
use std::path::Path;

use normpath::BasePath;
use normpath::PathExt;

// https://github.com/dylni/normpath/pull/4#issuecomment-938596259
tj(r"X:\X:", r"ABC", r"X:\X:\ABC");
tj(r"\\?\X:\X:", r"ABC", r"\\?\X:\X:\ABC");

#[rustversion::attr(since(1.46.0), track_caller)]
fn tj(base: &str, path: &str, joined_path: &str) {
let joined_path = Path::new(joined_path);
assert_eq!(joined_path, BasePath::try_new(base).unwrap().join(path));
common::assert_eq(joined_path, joined_path.normalize_virtually());
}
}

0 comments on commit da9b7b2

Please sign in to comment.