Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / quota / SanitizationUtils.cpp
blob12462823b87a4937c8c938b32a9ba07c33bd0243
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "SanitizationUtils.h"
9 #include <string>
11 #include "mozilla/dom/quota/QuotaManager.h"
12 #include "nsString.h"
14 namespace mozilla::dom::quota {
16 nsAutoCString MakeSanitizedOriginCString(const nsACString& aOrigin) {
17 #ifdef XP_WIN
18 NS_ASSERTION(!strcmp(QuotaManager::kReplaceChars,
19 FILE_ILLEGAL_CHARACTERS FILE_PATH_SEPARATOR),
20 "Illegal file characters have changed!");
21 #endif
23 nsAutoCString res{aOrigin};
25 res.ReplaceChar(QuotaManager::kReplaceChars, '+');
27 return res;
30 nsAutoString MakeSanitizedOriginString(const nsACString& aOrigin) {
31 // An origin string is ASCII-only, since it is obtained via
32 // nsIPrincipal::GetOrigin, which returns an ACString.
33 return NS_ConvertASCIItoUTF16(MakeSanitizedOriginCString(aOrigin));
36 } // namespace mozilla::dom::quota