SanitizationUtils.cpp (1127B)
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/. */ 6 7 #include "SanitizationUtils.h" 8 9 #include "mozilla/dom/quota/QuotaManager.h" 10 #include "nsString.h" 11 12 namespace mozilla::dom::quota { 13 14 nsAutoCString MakeSanitizedOriginCString(const nsACString& aOrigin) { 15 #ifdef XP_WIN 16 NS_ASSERTION(!strcmp(QuotaManager::kReplaceChars, 17 FILE_ILLEGAL_CHARACTERS FILE_PATH_SEPARATOR), 18 "Illegal file characters have changed!"); 19 #endif 20 21 nsAutoCString res{aOrigin}; 22 23 res.ReplaceChar(QuotaManager::kReplaceChars, '+'); 24 25 return res; 26 } 27 28 nsAutoString MakeSanitizedOriginString(const nsACString& aOrigin) { 29 // An origin string is ASCII-only, since it is obtained via 30 // nsIPrincipal::GetOrigin, which returns an ACString. 31 return NS_ConvertASCIItoUTF16(MakeSanitizedOriginCString(aOrigin)); 32 } 33 34 } // namespace mozilla::dom::quota