Bug 458252: local file paths are wrong on windows mobile r=dougt sr=bsmedberg
authorBrad Lassey <blassey@mozilla.com>
Mon, 20 Oct 2008 13:03:20 -0400
changeset 20674 6a0475a370b1087a5981c48494af9c81c563b7ca
parent 20673 504f57c097a1f751b081c929d0295b043a93fe6b
child 20675 0db169d84c728e43e387eb5b71bcca789f6c8b79
child 20817 f75212e4751c21883153a1e9eebf7d9d5d090e98
push idunknown
push userunknown
push dateunknown
reviewersdougt, bsmedberg
bugs458252
milestone1.9.1b2pre
Bug 458252: local file paths are wrong on windows mobile r=dougt sr=bsmedberg
netwerk/base/src/nsURLHelperWin.cpp
xpcom/io/nsLocalFileWin.cpp
--- a/netwerk/base/src/nsURLHelperWin.cpp
+++ b/netwerk/base/src/nsURLHelperWin.cpp
@@ -53,18 +53,24 @@ net_GetURLSpecFromFile(nsIFile *aFile, n
     // construct URL spec from file path
     rv = aFile->GetPath(path);
     if (NS_FAILED(rv)) return rv;
   
     // Replace \ with / to convert to an url
     path.ReplaceChar(PRUnichar(0x5Cu), PRUnichar(0x2Fu));
 
     nsCAutoString escPath;
+
+    // Windows Desktop paths beging with a drive letter, so need an 'extra'
+    // slash at the begining
+#ifdef WINCE  //  /Windows  => file:///Windows
+    NS_NAMED_LITERAL_CSTRING(prefix, "file://");
+#else  // C:\Windows =>  file:///C:/Windows
     NS_NAMED_LITERAL_CSTRING(prefix, "file:///");
-  
+#endif  
     // Escape the path with the directory mask
     NS_ConvertUTF16toUTF8 ePath(path);
     if (NS_EscapeURL(ePath.get(), -1, esc_Directory+esc_Forced, escPath))
         escPath.Insert(prefix, 0);
     else
         escPath.Assign(prefix + ePath);
 
     // esc_Directory does not escape the semicolons, so if a filename 
@@ -128,19 +134,21 @@ net_GetFileFromURLSpec(const nsACString 
         path += '.';
         NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path);
     }
     
     NS_UnescapeURL(path);
     if (path.Length() != strlen(path.get()))
         return NS_ERROR_FILE_INVALID_PATH;
 
+#ifndef WINCE
     // remove leading '\'
     if (path.CharAt(0) == '\\')
         path.Cut(0, 1);
+#endif
 
     if (IsUTF8(path))
         rv = localFile->InitWithPath(NS_ConvertUTF8toUTF16(path));
         // XXX In rare cases, a valid UTF-8 string can be valid as a native 
         // encoding (e.g. 0xC5 0x83 is valid both as UTF-8 and Windows-125x).
         // However, the chance is very low that a meaningful word in a legacy
         // encoding is valid as UTF-8.
     else 
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -895,22 +895,26 @@ nsLocalFile::InitWithPath(const nsAStrin
     PRUnichar secondChar = *(++begin);
 
     // just do a sanity check.  if it has any forward slashes, it is not a Native path
     // on windows.  Also, it must have a colon at after the first char.
 
     PRUnichar *path = nsnull;
     PRInt32 pathLen = 0;
 
-    if ( ( (secondChar == L':') && !FindCharInReadable(L'/', begin, end) ) ||  // normal path
-#ifdef WINCE
-         ( (firstChar == L'\\') )   // wince absolute path or network path
+    if (( 
+         !FindCharInReadable(L'/', begin, end) )   //normal path
+#ifndef WINCE
+        && (secondChar == L':') ||  // additional normal path condition
+        (secondChar == L'\\') &&    // addtional network path condition 
 #else
-         ( (firstChar == L'\\') && (secondChar == L'\\') )   // network path
-#endif
+        ||
+#endif 
+        (firstChar == L'\\')    // wince absolute path or network path
+
          )
     {
         // This is a native path
         path = ToNewUnicode(filePath);
         pathLen = filePath.Length();
     }
 
     if (path == nsnull) {