#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/url_formatter/url_fixer.h"
#include <stddef.h>
#include <string_view>
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/i18n/char_iterator.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/url_formatter/url_formatter.h"
#include "net/base/filename_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_file.h"
#include "url/url_util.h"
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include "base/path_service.h"
#endif
namespace url_formatter {
const char* home_directory_override = …;
namespace {
const char kChromeUIScheme[] = …;
const char kDevToolsScheme[] = …;
const char kChromeUIDefaultHost[] = …;
const char kViewSourceScheme[] = …;
const size_t kMaxFixupURLDepth = …;
url::Component UTF8ComponentToUTF16Component(
const std::string& text_utf8,
const url::Component& component_utf8) { … }
void UTF8PartsToUTF16Parts(const std::string& text_utf8,
const url::Parsed& parts_utf8,
url::Parsed* parts) { … }
base::TrimPositions TrimWhitespace(const std::u16string& input,
base::TrimPositions positions,
std::string* output) { … }
base::TrimPositions TrimWhitespaceUTF8(const std::string& input,
base::TrimPositions positions,
std::string* output) { … }
void PrepareStringForFileOps(const base::FilePath& text, std::string* output) { … }
bool ValidPathForFile(const std::string& text, base::FilePath* full_path) { … }
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
std::string FixupHomedir(const std::string& text) { … }
#endif
std::string FixupPath(const std::string& text) { … }
void AddDesiredTLD(const std::string& desired_tld, std::string* domain) { … }
inline void FixupUsername(const std::string& text,
const url::Component& part,
std::string* url) { … }
inline void FixupPassword(const std::string& text,
const url::Component& part,
std::string* url) { … }
void FixupHost(const std::string& text,
const url::Component& part,
bool has_scheme,
const std::string& desired_tld,
std::string* url) { … }
void FixupPort(const std::string& text,
const url::Component& part,
std::string* url) { … }
inline void FixupPath(const std::string& text,
const url::Component& part,
std::string* url) { … }
inline void FixupQuery(const std::string& text,
const url::Component& part,
std::string* url) { … }
inline void FixupRef(const std::string& text,
const url::Component& part,
std::string* url) { … }
bool HasPort(const std::string& original_text,
const url::Component& scheme_component) { … }
bool GetValidScheme(const std::string& text,
url::Component* scheme_component,
std::string* canon_scheme) { … }
std::string SegmentURLInternal(std::string* text, url::Parsed* parts) { … }
}
std::string SegmentURL(const std::string& text, url::Parsed* parts) { … }
std::u16string SegmentURL(const std::u16string& text, url::Parsed* parts) { … }
GURL FixupURLInternal(const std::string& text,
const std::string& desired_tld,
size_t depth) { … }
GURL FixupURL(const std::string& text, const std::string& desired_tld) { … }
GURL FixupRelativeFile(const base::FilePath& base_dir,
const base::FilePath& text) { … }
void OffsetComponent(int offset, url::Component* part) { … }
bool IsEquivalentScheme(const std::string& scheme1,
const std::string& scheme2) { … }
}