mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
This is to prepare for custom search engines. If we use AK::format, it would be trivial for a user (or bad actor) to come up with a template search engine URL that ultimately crashes the browser due to internal assertions in AK::format. For example: https://example.com/crash={1} Rather than coming up with a complicated pre-format validator, let's just not use AK::format. Custom URLs will signify their template query parameters with "%s". So we can do the same with our built-in engines. When it comes time to format the URL, we will do a simple string replacement.
39 lines
933 B
C++
39 lines
933 B
C++
/*
|
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Optional.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibURL/URL.h>
|
|
#include <LibWebView/SearchEngine.h>
|
|
|
|
namespace WebView {
|
|
|
|
enum class AppendTLD {
|
|
No,
|
|
Yes,
|
|
};
|
|
Optional<URL::URL> sanitize_url(StringView, Optional<SearchEngine> const& search_engine = {}, AppendTLD = AppendTLD::No);
|
|
Vector<URL::URL> sanitize_urls(ReadonlySpan<ByteString> raw_urls, URL::URL const& new_tab_page_url);
|
|
|
|
struct URLParts {
|
|
StringView scheme_and_subdomain;
|
|
StringView effective_tld_plus_one;
|
|
StringView remainder;
|
|
};
|
|
Optional<URLParts> break_url_into_parts(StringView url);
|
|
|
|
// These are both used for the "right-click -> copy FOO" interaction for links.
|
|
enum class URLType {
|
|
Email,
|
|
Telephone,
|
|
Other,
|
|
};
|
|
URLType url_type(URL::URL const&);
|
|
String url_text_to_copy(URL::URL const&);
|
|
|
|
}
|