зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1534339 - make OriginAttributes deserializable; r=baku
`CreateSuffix` is irreversible by `PopulateFromSuffix` because it uses a multi-to-one mapping. Since only ':' will happen in a IPv6 format, we can make it a 1-to-1 mapping so that the `firstPartyDomain` is consistent after `CreateSuffix` and `PopulateFromSuffix`. Differential Revision: https://phabricator.services.mozilla.com/D47910 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9157afe622
Коммит
489786654f
|
@ -13,6 +13,9 @@
|
|||
#include "nsIURI.h"
|
||||
#include "nsURLHelper.h"
|
||||
|
||||
static const char kSourceChar = ':';
|
||||
static const char kSanitizedChar = '+';
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using dom::URLParams;
|
||||
|
@ -140,8 +143,7 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
|
|||
|
||||
if (!mFirstPartyDomain.IsEmpty()) {
|
||||
nsAutoString sanitizedFirstPartyDomain(mFirstPartyDomain);
|
||||
sanitizedFirstPartyDomain.ReplaceChar(
|
||||
dom::quota::QuotaManager::kReplaceChars, '+');
|
||||
sanitizedFirstPartyDomain.ReplaceChar(kSourceChar, kSanitizedChar);
|
||||
|
||||
params.Set(NS_LITERAL_STRING("firstPartyDomain"),
|
||||
sanitizedFirstPartyDomain);
|
||||
|
@ -150,7 +152,7 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
|
|||
if (!mGeckoViewSessionContextId.IsEmpty()) {
|
||||
nsAutoString sanitizedGeckoViewUserContextId(mGeckoViewSessionContextId);
|
||||
sanitizedGeckoViewUserContextId.ReplaceChar(
|
||||
dom::quota::QuotaManager::kReplaceChars, '+');
|
||||
dom::quota::QuotaManager::kReplaceChars, kSanitizedChar);
|
||||
|
||||
params.Set(NS_LITERAL_STRING("geckoViewUserContextId"),
|
||||
sanitizedGeckoViewUserContextId);
|
||||
|
@ -237,7 +239,9 @@ class MOZ_STACK_CLASS PopulateFromSuffixIterator final
|
|||
|
||||
if (aName.EqualsLiteral("firstPartyDomain")) {
|
||||
MOZ_RELEASE_ASSERT(mOriginAttributes->mFirstPartyDomain.IsEmpty());
|
||||
mOriginAttributes->mFirstPartyDomain.Assign(aValue);
|
||||
nsAutoString firstPartyDomain(aValue);
|
||||
firstPartyDomain.ReplaceChar(kSanitizedChar, kSourceChar);
|
||||
mOriginAttributes->mFirstPartyDomain.Assign(firstPartyDomain);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ static void TestFPD(const nsAString& spec, const nsAString& fpd) {
|
|||
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
|
||||
attrs.SetFirstPartyDomain(true, url);
|
||||
EXPECT_TRUE(attrs.mFirstPartyDomain.Equals(fpd));
|
||||
|
||||
TestSuffix(attrs);
|
||||
}
|
||||
|
||||
TEST(OriginAttributes, Suffix_default)
|
||||
|
|
Загрузка…
Ссылка в новой задаче