Bug 1852071: Created a new helper IsUUIDOrigin to check if a given string is in UUID format.r=dom-storage-reviewers,janv

Depends on D187540

Differential Revision: https://phabricator.services.mozilla.com/D185112
This commit is contained in:
hsingh 2023-09-07 20:53:47 +00:00
Родитель 532ee3b42f
Коммит 29995f21a6
4 изменённых файлов: 38 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,8 @@
#include "OriginParser.h"
#include <regex>
#include "mozilla/OriginAttributes.h"
#include "mozilla/dom/quota/Constants.h"
#include "mozilla/dom/quota/QuotaCommon.h"
@ -474,4 +476,12 @@ void OriginParser::HandleTrailingSeparator() {
mState = eHandledTrailingSeparator;
}
bool IsUUIDOrigin(const nsCString& aOrigin) {
static const std::regex pattern(
"^uuid://[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab"
"][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$");
return regex_match(aOrigin.get(), pattern);
}
} // namespace mozilla::dom::quota

Просмотреть файл

@ -104,6 +104,8 @@ class MOZ_STACK_CLASS OriginParser final {
void HandleTrailingSeparator();
};
bool IsUUIDOrigin(const nsCString& aOrigin);
} // namespace dom::quota
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OriginParser.h"
#include "gtest/gtest.h"
using namespace mozilla::dom::quota;
TEST(OriginParser_IsUUIDOrigin, Valid)
{ EXPECT_TRUE(IsUUIDOrigin("uuid://1ef9867c-e754-4303-a18b-684f0321f6e2"_ns)); }
TEST(OriginParser_IsUUIDOrigin, Invalid)
{
EXPECT_FALSE(IsUUIDOrigin("Invalid UUID Origin"_ns));
EXPECT_FALSE(IsUUIDOrigin("1ef9867c-e754-4303-a18b-684f0321f6e2"_ns));
EXPECT_FALSE(IsUUIDOrigin("uuid://1ef9867c-e754-4303-a18b"_ns));
EXPECT_FALSE(IsUUIDOrigin("uuid+++1ef9867c-e754-4303-a18b-684f0321f6e2"_ns));
}

Просмотреть файл

@ -22,6 +22,7 @@ UNIFIED_SOURCES = [
"TestFileOutputStream.cpp",
"TestFlatten.cpp",
"TestForwardDecls.cpp",
"TestOriginParser.cpp",
"TestPersistenceType.cpp",
"TestQMResult.cpp",
"TestQuotaCommon.cpp",