Bug 1324251 - Unconditionally parse windows drive letters in file paths; r?valentin draft
authorManish Goregaokar <manishearth@gmail.com>
Sun, 18 Dec 2016 18:38:01 -0800
changeset 451532 5d35595a652aa588d32020518e19a20cbca33995
parent 450591 34a1ab064cb5b868fa75cb74d052e978eb34d6c1
child 451533 3eb051ebbd6fb9aa671d916de07675310f2a19eb
push id39222
push userbmo:manishearth@gmail.com
push dateTue, 20 Dec 2016 16:37:46 +0000
reviewersvalentin
bugs1324251
milestone53.0a1
Bug 1324251 - Unconditionally parse windows drive letters in file paths; r?valentin MozReview-Commit-ID: 6nBPHYHNprF
netwerk/base/nsStandardURL.cpp
netwerk/base/nsURLParsers.cpp
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -975,16 +975,27 @@ nsStandardURL::BuildNormalizedSpec(const
                                    &diff);
         }
         // calculate corrected path length
         mPath.mLen = i - mPath.mPos;
     }
 
     buf[i] = '\0';
 
+    // https://url.spec.whatwg.org/#path-state (1.4.1.2)
+    // https://url.spec.whatwg.org/#windows-drive-letter
+    if (SegmentIs(buf, mScheme, "file")) {
+        char* path = &buf[mPath.mPos];
+        if (mPath.mLen >= 3 && path[0] == '/'
+            && nsCRT::IsAsciiAlpha(path[1])
+            && path[2] == '|') {
+            buf[mPath.mPos + 2] = ':';
+        }
+    }
+
     if (mDirectory.mLen > 1) {
         netCoalesceFlags coalesceFlag = NET_COALESCE_NORMAL;
         if (SegmentIs(buf,mScheme,"ftp")) {
             coalesceFlag = (netCoalesceFlags) (coalesceFlag 
                                         | NET_COALESCE_ALLOW_RELATIVE_ROOT
                                         | NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
         }
         CoalescePath(coalesceFlag, buf + mDirectory.mPos);
--- a/netwerk/base/nsURLParsers.cpp
+++ b/netwerk/base/nsURLParsers.cpp
@@ -376,28 +376,27 @@ nsNoAuthURLParser::ParseAfterScheme(cons
     case 0:
     case 1:
         break;
     case 2:
         {
             const char *p = nullptr;
             if (specLen > 2) {
                 // looks like there is an authority section
-#if defined(XP_WIN)
+
                 // if the authority looks like a drive number then we
                 // really want to treat it as part of the path
                 // [a-zA-Z][:|]{/\}
                 // i.e one of:   c:   c:\foo  c:/foo  c|  c|\foo  c|/foo
                 if ((specLen > 3) && (spec[3] == ':' || spec[3] == '|') &&
                     nsCRT::IsAsciiAlpha(spec[2]) &&
                     ((specLen == 4) || (spec[4] == '/') || (spec[4] == '\\'))) {
                     pos = 1;
                     break;  
-                } 
-#endif
+                }
                 // Ignore apparent authority; path is everything after it
                 for (p = spec + 2; p < spec + specLen; ++p) {
                     if (*p == '/' || *p == '?' || *p == '#')
                         break;
                 }
             }
             SET_RESULT(auth, 0, -1);
             if (p && p != spec+specLen)