diff --git a/src/kits/network/libnetapi/NetworkCookie.cpp b/src/kits/network/libnetapi/NetworkCookie.cpp index bb85614f2e..a9f3a333c5 100644 --- a/src/kits/network/libnetapi/NetworkCookie.cpp +++ b/src/kits/network/libnetapi/NetworkCookie.cpp @@ -38,6 +38,13 @@ BNetworkCookie::BNetworkCookie(const char* name, const char* value, fValue = value; SetDomain(url.Host()); + + if(url.Protocol() == "file" && url.Host().Length() == 0) + { + SetDomain("localhost"); + // make sure cookies set from a file:// URL are stored somewhere. + } + SetPath(_DefaultPathForUrl(url)); } @@ -93,6 +100,13 @@ BNetworkCookie::ParseCookieString(const BString& string, const BUrl& url) SetPath(_DefaultPathForUrl(url)); SetDomain(url.Host()); fHostOnly = true; + if(url.Protocol() == "file" && url.Host().Length() == 0) + { + fDomain = "localhost"; + // make sure cookies set from a file:// URL are stored somewhere. + // not going through SetDomain as it requires at least one '.' + // in the domain (to avoid setting cookies on TLDs). + } BString name; BString value; @@ -166,13 +180,12 @@ BNetworkCookie::ParseCookieString(const BString& string, const BUrl& url) } } - if (!IsValidForDomain(url.Host())) { + if (!IsValidForUrl(url)) { // Invalidate the cookie. _Reset(); return B_NOT_ALLOWED; } - return result; } @@ -423,6 +436,9 @@ BNetworkCookie::IsValidForUrl(const BUrl& url) const if (Secure() && url.Protocol() != "https") return false; + if (url.Protocol() == "file") + return Domain() == "localhost" && IsValidForPath(url.Path()); + return IsValidForDomain(url.Host()) && IsValidForPath(url.Path()); } diff --git a/src/kits/network/libnetapi/NetworkCookieJar.cpp b/src/kits/network/libnetapi/NetworkCookieJar.cpp index ae97f37dc0..d4a9fd31f3 100644 --- a/src/kits/network/libnetapi/NetworkCookieJar.cpp +++ b/src/kits/network/libnetapi/NetworkCookieJar.cpp @@ -591,8 +591,12 @@ BNetworkCookieJar::UrlIterator::UrlIterator(const BNetworkCookieJar* cookieJar, { BString domain = url.Host(); - if (!domain.Length()) - return; + if (!domain.Length()) { + if (url.Protocol() == "file") + domain = "localhost"; + else + return; + } fIterator = new(std::nothrow) PrivateIterator( fCookieJar->fCookieHashMap->fHashMap.GetIterator());