Bug 1324251 - Unconditionally parse windows drive letters in file paths; r?valentin
MozReview-Commit-ID: 6nBPHYHNprF
--- 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)