Skip to content

Commit

Permalink
auto merge of #11579 : kballard/rust/windows-path-join, r=erickt
Browse files Browse the repository at this point in the history
WindowsPath::new("C:").join("a") produces r"C:�". This is incorrect.
It should produce "C:a".
  • Loading branch information
bors committed Jan 16, 2014
2 parents 793f740 + c57920b commit 6361c1d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,13 @@ impl GenericPathUnsafe for Path {
let mut s = str::with_capacity(me.repr.len() + 1 + pathlen);
s.push_str(me.repr);
let plen = me.prefix_len();
if !(me.repr.len() > plen && me.repr[me.repr.len()-1] == sep as u8) {
s.push_char(sep);
// if me is "C:" we don't want to add a path separator
match me.prefix {
Some(DiskPrefix) if me.repr.len() == plen => (),
_ if !(me.repr.len() > plen && me.repr[me.repr.len()-1] == sep as u8) => {
s.push_char(sep);
}
_ => ()
}
match path_ {
None => s.push_str(path),
Expand Down Expand Up @@ -1549,6 +1554,8 @@ mod tests {
t!(s: "C:a\\b\\c", "C:d", "C:a\\b\\c\\d");
t!(s: "C:a\\b", "..\\..\\..\\c", "C:..\\c");
t!(s: "C:\\a\\b", "..\\..\\..\\c", "C:\\c");
t!(s: "C:", r"a\b\c", r"C:a\b\c");
t!(s: "C:", r"..\a", r"C:..\a");
t!(s: "\\\\server\\share\\foo", "bar", "\\\\server\\share\\foo\\bar");
t!(s: "\\\\server\\share\\foo", "..\\..\\bar", "\\\\server\\share\\bar");
t!(s: "\\\\server\\share\\foo", "C:baz", "C:baz");
Expand Down

0 comments on commit 6361c1d

Please sign in to comment.