Bug 960962 - OS.File normalization and concatenation issues on Windows. r=Yoric, a=sledru
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 10 Feb 2014 19:59:29 +0100
changeset 182846 279f0dc7ee4208bb10db66a77ba2a360aaec62c0
parent 182845 ed268cf8ef4b8844081a801a6185c53745245f27
child 182847 5be150c0e8a15bc7fa3cb0362b40f5d209f9fa6e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric, sledru
bugs960962
milestone29.0a2
Bug 960962 - OS.File normalization and concatenation issues on Windows. r=Yoric, a=sledru
toolkit/components/osfile/modules/ospath_win.jsm
toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js
toolkit/components/osfile/tests/xpcshell/test_path.js
--- a/toolkit/components/osfile/modules/ospath_win.jsm
+++ b/toolkit/components/osfile/modules/ospath_win.jsm
@@ -137,27 +137,26 @@ exports.dirname = dirname;
  * Under Windows, this will return "$TMP\foo\bar".
  */
 let join = function(...path) {
   let paths = [];
   let root;
   let absolute = false;
   for each(let subpath in path) {
     let drive = this.winGetDrive(subpath);
-    let abs   = this.winIsAbsolute(subpath);
     if (drive) {
       root = drive;
       let component = trimBackslashes(subpath.slice(drive.length));
       if (component) {
         paths = [component];
       } else {
         paths = [];
       }
-      absolute = abs;
-    } else if (abs) {
+      absolute = true;
+    } else if (this.winIsAbsolute(subpath)) {
       paths = [trimBackslashes(subpath)];
       absolute = true;
     } else {
       paths.push(trimBackslashes(subpath));
     }
   }
   let result = "";
   if (root) {
@@ -254,17 +253,17 @@ let normalize = function(path) {
       break;
     default:
       stack.push(v);
     }
   });
 
   // Put everything back together
   let result = stack.join("\\");
-  if (absolute) {
+  if (absolute || root) {
     result = "\\" + result;
   }
   if (root) {
     result = root + result;
   }
   return result;
 };
 exports.normalize = normalize;
--- a/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js
@@ -84,18 +84,21 @@ function run_test() {
   ];
 
   for (let path of paths) {
     // convert that to a uri using FileUtils and Services, which toFileURI is trying to model
     let file = FileUtils.File(path);
     let uri = Services.io.newFileURI(file).spec;
     do_check_eq(uri, OS.Path.toFileURI(path));
 
-    // keep the resulting URI to try the reverse
-    uris.push(uri)
+    // keep the resulting URI to try the reverse, except for "C:\" for which the
+    // behavior of nsIFileURL and OS.File is inconsistent
+    if (path != "C:\\") {
+      uris.push(uri);
+    }
   }
 
   for (let uri of uris) {
     // convert URIs to paths with nsIFileURI, which fromFileURI is trying to model
     let path = Services.io.newURI(uri, null, null).QueryInterface(Components.interfaces.nsIFileURL).file.path;
     do_check_eq(path, OS.Path.fromFileURI(uri));
   }
 
--- a/toolkit/components/osfile/tests/xpcshell/test_path.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_path.js
@@ -63,50 +63,55 @@ function run_test()
   do_check_eq(Win.dirname("c:abc"), "c:");
   let options = {
     winNoDrive: true
   };
   do_check_eq(Win.dirname("c:a\\b", options), "a");
   do_check_eq(Win.dirname("c:a\\b\\", options), "a\\b");
   do_check_eq(Win.dirname("c:a\\\\\\\\b", options), "a");
   do_check_eq(Win.dirname("c:abc", options), ".");
+  do_check_eq(Win.join("c:", "abc"), "c:\\abc", "join c:,abc");
 
+  do_check_eq(Win.normalize("c:"), "c:\\");
+  do_check_eq(Win.normalize("c:\\"), "c:\\");
   do_check_eq(Win.normalize("c:\\a\\b\\c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:\\a\\b\\\\\\\\c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:\\\\\\\\a\\b\\c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:\\a\\b\\c\\\\\\"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:\\a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f");
-  do_check_eq(Win.normalize("c:a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:d\\e\\f");
+  do_check_eq(Win.normalize("c:a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f");
   do_check_fail(function() Win.normalize("c:\\a\\b\\c\\..\\..\\..\\..\\d\\e\\f"));
 
+  do_check_eq(Win.join("c:\\", "foo"), "c:\\foo", "join c:\,foo");
   do_check_eq(Win.join("c:\\tmp", "foo", "bar"), "c:\\tmp\\foo\\bar", "join c:\\tmp,foo,bar");
   do_check_eq(Win.join("c:\\tmp", "\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,\\foo,bar");
   do_check_eq(Win.join("c:\\tmp", "c:\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:\\foo,bar");
-  do_check_eq(Win.join("c:\\tmp", "c:foo", "bar"), "c:foo\\bar", "join c:\\tmp,c:foo,bar");
+  do_check_eq(Win.join("c:\\tmp", "c:foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:foo,bar");
   do_check_eq(Win.winGetDrive("c:"), "c:");
   do_check_eq(Win.winGetDrive("c:\\"), "c:");
   do_check_eq(Win.winGetDrive("c:abc"), "c:");
   do_check_eq(Win.winGetDrive("c:abc\\d\\e\\f\\g"), "c:");
   do_check_eq(Win.winGetDrive("c:\\abc"), "c:");
   do_check_eq(Win.winGetDrive("c:\\abc\\d\\e\\f\\g"), "c:");
 
   do_print("Forwardslash-separated, no drive");
   do_check_eq(Win.normalize("/a/b/c"), "\\a\\b\\c");
   do_check_eq(Win.normalize("/a/b////c"), "\\a\\b\\c");
   do_check_eq(Win.normalize("/a/b/c///"), "\\a\\b\\c");
   do_check_eq(Win.normalize("/a/b/c/../../../d/e/f"), "\\d\\e\\f");
   do_check_eq(Win.normalize("a/b/c/../../../d/e/f"), "d\\e\\f");
 
   do_print("Forwardslash-separated, with a drive");
+  do_check_eq(Win.normalize("c:/"), "c:\\");
   do_check_eq(Win.normalize("c:/a/b/c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:/a/b////c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:////a/b/c"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:/a/b/c///"), "c:\\a\\b\\c");
   do_check_eq(Win.normalize("c:/a/b/c/../../../d/e/f"), "c:\\d\\e\\f");
-  do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:d\\e\\f");
+  do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:\\d\\e\\f");
 
   do_print("Backslash-separated, UNC-style");
   do_check_eq(Win.basename("\\\\a\\b"), "b");
   do_check_eq(Win.basename("\\\\a\\b\\"), "");
   do_check_eq(Win.basename("\\\\abc"), "");
   do_check_eq(Win.dirname("\\\\a\\b"), "\\\\a");
   do_check_eq(Win.dirname("\\\\a\\b\\"), "\\\\a\\b");
   do_check_eq(Win.dirname("\\\\a\\\\\\\\b"), "\\\\a");