LibWebView: Allow data URLs in sanitize_url

Allow navigation to data URLs from browser UI.
This commit is contained in:
Luke Warlow 2024-06-24 02:12:19 +01:00 committed by Tim Flynn
parent ebdb92eef6
commit 6014727c20
Notes: sideshowbarker 2024-07-18 05:01:22 +09:00
2 changed files with 17 additions and 8 deletions

View file

@ -17,6 +17,14 @@ static void compare_url_parts(StringView url, WebView::URLParts const& expected)
EXPECT_EQ(result->remainder, expected.remainder);
}
static bool is_sanitized_url_the_same(StringView url)
{
auto sanitized_url = WebView::sanitize_url(url);
if (!sanitized_url.has_value())
return false;
return sanitized_url->to_string().value() == url;
}
TEST_CASE(invalid_url)
{
EXPECT(!WebView::break_url_into_parts(""sv).has_value());
@ -82,13 +90,6 @@ TEST_CASE(http_url)
TEST_CASE(about_url)
{
auto is_sanitized_url_the_same = [](StringView url) {
auto sanitized_url = WebView::sanitize_url(url);
if (!sanitized_url.has_value())
return false;
return sanitized_url->to_string().value() == url;
};
EXPECT(!is_sanitized_url_the_same("about"sv));
EXPECT(!is_sanitized_url_the_same("about blabla:"sv));
EXPECT(!is_sanitized_url_the_same("blabla about:"sv));
@ -96,3 +97,11 @@ TEST_CASE(about_url)
EXPECT(is_sanitized_url_the_same("about:about"sv));
EXPECT(is_sanitized_url_the_same("about:version"sv));
}
TEST_CASE(data_url)
{
EXPECT(is_sanitized_url_the_same("data:text/html"sv));
EXPECT(!is_sanitized_url_the_same("data text/html"sv));
EXPECT(!is_sanitized_url_the_same("text/html data:"sv));
}

View file

@ -62,7 +62,7 @@ Optional<URL::URL> sanitize_url(StringView url, Optional<StringView> search_engi
}
ByteString url_with_scheme = url;
if (!(url_with_scheme.starts_with("about:"sv) || url_with_scheme.contains("://"sv)))
if (!(url_with_scheme.starts_with("about:"sv) || url_with_scheme.contains("://"sv) || url_with_scheme.starts_with("data:"sv)))
url_with_scheme = ByteString::formatted("https://{}"sv, url_with_scheme);
auto result = URL::create_with_url_or_path(url_with_scheme);