Fix minor path handling issue in path package.

BUG=

Review URL: https://codereview.chromium.org//11876012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/path@17006 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/lib/path.dart b/lib/path.dart
index cc882f4..f27d558 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -438,10 +438,14 @@
 
     // If the root prefixes don't match (for example, different drive letters
     // on Windows), then there is no relative path, so just return the absolute
-    // one.
-    // TODO(rnystrom): Drive letters are case-insentive on Windows. Should
-    // handle "C:\" and "c:\" being the same root.
-    if (fromParsed.root != pathParsed.root) return pathParsed.toString();
+    // one. In Windows, drive letters are case-insenstive and we allow
+    // calculation of relative paths, even if a path has not been normalized.
+    if (fromParsed.root != pathParsed.root &&
+        ((fromParsed.root ==  null || pathParsed.root == null) ||
+          fromParsed.root.toLowerCase().replaceAll('/', '\\') !=
+          pathParsed.root.toLowerCase().replaceAll('/', '\\'))) {
+      return pathParsed.toString();
+    }
 
     // Strip off their common prefix.
     while (fromParsed.parts.length > 0 && pathParsed.parts.length > 0 &&
@@ -644,6 +648,10 @@
     parts = newParts;
     separators = newSeparators;
 
+    // Normalize the Windows root if needed.
+    if (root != null && style == Style.windows) {
+      root = root.replaceAll('/', '\\');
+    }
     removeTrailingSeparators();
   }
 
diff --git a/test/path_windows_test.dart b/test/path_windows_test.dart
index c3ee6fb..12e370b 100644
--- a/test/path_windows_test.dart
+++ b/test/path_windows_test.dart
@@ -216,7 +216,7 @@
       expect(builder.normalize('.'), '.');
       expect(builder.normalize('..'), '..');
       expect(builder.normalize('a'), 'a');
-      expect(builder.normalize('C:/'), r'C:/');
+      expect(builder.normalize('C:/'), r'C:\');
       expect(builder.normalize(r'C:\'), r'C:\');
       expect(builder.normalize(r'\\'), r'\\');
     });
@@ -250,7 +250,7 @@
       expect(builder.normalize(r'\\..\..\..'), r'\\');
       expect(builder.normalize(r'\\..\../..\a'), r'\\a');
       expect(builder.normalize(r'c:\..'), r'c:\');
-      expect(builder.normalize(r'A:/..\..\..'), r'A:/');
+      expect(builder.normalize(r'A:/..\..\..'), r'A:\');
       expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a');
       expect(builder.normalize(r'a\..'), '.');
       expect(builder.normalize(r'a\b\..'), 'a');
@@ -282,6 +282,10 @@
         expect(builder.relative(r'C:\root\path\a'), 'a');
         expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt');
         expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt');
+        expect(builder.relative(r'C:/'), r'..\..');
+        expect(builder.relative(r'C:/root'), '..');
+        expect(builder.relative(r'c:\'), r'..\..');
+        expect(builder.relative(r'c:\root'), '..');
       });
 
       test('given absolute path outside of root', () {
@@ -289,6 +293,10 @@
         expect(builder.relative(r'C:\root\path\a'), 'a');
         expect(builder.relative(r'C:\root\path\a\b.txt'), r'a\b.txt');
         expect(builder.relative(r'C:\root\a\b.txt'), r'..\a\b.txt');
+        expect(builder.relative(r'C:/a/b'), r'..\..\a\b');
+        expect(builder.relative(r'C:/root/path/a'), 'a');
+        expect(builder.relative(r'c:\a\b'), r'..\..\a\b');
+        expect(builder.relative(r'c:\root\path\a'), 'a');
       });
 
       test('given absolute path on different drive', () {