mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibWebView: Use Unicode::parse_unicode_url for parsing URLs
This commit is contained in:
parent
58f08107b0
commit
0fe192dfd9
2 changed files with 21 additions and 3 deletions
|
@ -44,7 +44,7 @@ set(GENERATED_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibWebView webview)
|
serenity_lib(LibWebView webview)
|
||||||
target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibIPC LibProtocol LibJS LibWeb LibSQL)
|
target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibIPC LibProtocol LibJS LibWeb LibSQL LibUnicode)
|
||||||
target_compile_definitions(LibWebView PRIVATE ENABLE_PUBLIC_SUFFIX=$<BOOL:${ENABLE_PUBLIC_SUFFIX_DOWNLOAD}>)
|
target_compile_definitions(LibWebView PRIVATE ENABLE_PUBLIC_SUFFIX=$<BOOL:${ENABLE_PUBLIC_SUFFIX_DOWNLOAD}>)
|
||||||
|
|
||||||
if (SERENITYOS)
|
if (SERENITYOS)
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/LexicalPath.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
#include <LibUnicode/URL.h>
|
||||||
#include <LibWebView/URL.h>
|
#include <LibWebView/URL.h>
|
||||||
|
|
||||||
#if defined(ENABLE_PUBLIC_SUFFIX)
|
#if defined(ENABLE_PUBLIC_SUFFIX)
|
||||||
|
@ -16,16 +18,32 @@
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
|
static Optional<URL> create_url_with_url_or_path(String const& url_or_path)
|
||||||
|
{
|
||||||
|
auto url = Unicode::create_unicode_url(url_or_path);
|
||||||
|
if (!url.is_error() && url.value().is_valid())
|
||||||
|
return url.release_value();
|
||||||
|
|
||||||
|
auto path = LexicalPath::canonicalized_path(url_or_path.to_deprecated_string());
|
||||||
|
auto url_from_path = URL::create_with_file_scheme(path);
|
||||||
|
if (url_from_path.is_valid())
|
||||||
|
return url_from_path;
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
static Optional<URL> query_public_suffix_list(StringView url_string)
|
static Optional<URL> query_public_suffix_list(StringView url_string)
|
||||||
{
|
{
|
||||||
auto out = MUST(String::from_utf8(url_string));
|
auto out = MUST(String::from_utf8(url_string));
|
||||||
if (!out.contains("://"sv))
|
if (!out.contains("://"sv))
|
||||||
out = MUST(String::formatted("https://{}"sv, out));
|
out = MUST(String::formatted("https://{}"sv, out));
|
||||||
|
|
||||||
auto url = URL::create_with_url_or_path(out.to_deprecated_string());
|
auto maybe_url = create_url_with_url_or_path(out);
|
||||||
if (!url.is_valid())
|
if (!maybe_url.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
auto url = maybe_url.release_value();
|
||||||
|
|
||||||
if (url.host().has<URL::IPv4Address>() || url.host().has<URL::IPv6Address>())
|
if (url.host().has<URL::IPv4Address>() || url.host().has<URL::IPv6Address>())
|
||||||
return url;
|
return url;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue