about summary refs log tree commit diff
path: root/src/libstd/path
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-01-15 12:53:56 -0800
committerKevin Ballard <kevin@sb.org>2014-01-15 12:53:56 -0800
commitc57920b37b401ca364b6d4c99dc714f28988c7f0 (patch)
tree5cf8fc5d56e3f9614ecb693b78eaf4c89ededf96 /src/libstd/path
parent900893112570eea5a01c0573ae1fa1e3a72397e9 (diff)
downloadrust-c57920b37b401ca364b6d4c99dc714f28988c7f0.tar.gz
rust-c57920b37b401ca364b6d4c99dc714f28988c7f0.zip
path: Fix joining Windows path when the receiver is "C:"
WindowsPath::new("C:").join("a") produces r"C:\a". This is incorrect.
It should produce "C:a".
Diffstat (limited to 'src/libstd/path')
-rw-r--r--src/libstd/path/windows.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index 09b00be7e9d..f8d80599151 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -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),
@@ -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");