Commit 6dfcb949 authored by Liang-Heng Chen's avatar Liang-Heng Chen Committed by Georg Koppen
Browse files

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
parent b9e148eb
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@
#include "nsIURI.h"
#include "nsURLHelper.h"

static const char kSourceChar = ':';
static const char kSanitizedChar = '+';

namespace mozilla {

using dom::URLParams;
@@ -158,8 +161,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);
@@ -246,7 +248,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;
    }

+2 −0
Original line number Diff line number Diff line
@@ -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)