1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:17:34 +00:00

AK: Serialize URL hosts with 'concept-host-serializer'

In order to follow spec text to achieve this, we need to change the
underlying representation of a host in AK::URL to deserialized format.
Before this, we were parsing the host and then immediately serializing
it again.

Making that change resulted in a whole bunch of fallout.

After this change, callers can access the serialized data through
this concept-host-serializer. The functional end result of this
change is that IPv6 hosts are now correctly serialized to be
surrounded with '[' and ']'.
This commit is contained in:
Shannon Booth 2023-07-27 21:40:41 +12:00 committed by Andreas Kling
parent 768f070b86
commit 8751be09f9
36 changed files with 175 additions and 143 deletions

View file

@ -248,8 +248,8 @@ void URLProvider::query(DeprecatedString const& query, Function<void(Vector<Nonn
if (url.scheme().is_empty())
url.set_scheme("http");
if (url.host().is_empty())
url.set_host(query);
if (url.host().has<Empty>() || url.host() == String {})
url.set_host(String::from_deprecated_string(query).release_value_but_fixme_should_propagate_errors());
if (url.path_segment_count() == 0)
url.set_paths({ "" });

View file

@ -208,7 +208,10 @@ Optional<DeprecatedString> CookieJar::canonicalize_domain(const URL& url)
return {};
// FIXME: Implement RFC 5890 to "Convert each label that is not a Non-Reserved LDH (NR-LDH) label to an A-label".
return url.host().to_lowercase();
if (url.host().has<Empty>())
return {};
return url.serialized_host().release_value_but_fixme_should_propagate_errors().to_deprecated_string().to_lowercase();
}
bool CookieJar::domain_matches(DeprecatedString const& string, DeprecatedString const& domain_string)

View file

@ -107,10 +107,10 @@ void Tab::update_status(Optional<String> text_override, i32 count_waiting)
if (count_waiting == 0) {
// ex: "Loading google.com"
m_statusbar->set_text(String::formatted("Loading {}", m_navigating_url->host()).release_value_but_fixme_should_propagate_errors());
m_statusbar->set_text(String::formatted("Loading {}", m_navigating_url->serialized_host().release_value_but_fixme_should_propagate_errors()).release_value_but_fixme_should_propagate_errors());
} else {
// ex: "google.com is waiting on 5 resources"
m_statusbar->set_text(String::formatted("{} is waiting on {} resource{}", m_navigating_url->host(), count_waiting, count_waiting == 1 ? ""sv : "s"sv).release_value_but_fixme_should_propagate_errors());
m_statusbar->set_text(String::formatted("{} is waiting on {} resource{}", m_navigating_url->serialized_host().release_value_but_fixme_should_propagate_errors(), count_waiting, count_waiting == 1 ? ""sv : "s"sv).release_value_but_fixme_should_propagate_errors());
}
}

View file

@ -83,7 +83,7 @@ HelpWindow::HelpWindow(GUI::Window* parent)
m_webview = splitter.add<WebView::OutOfProcessWebView>();
m_webview->on_link_click = [this](auto& url, auto&, auto&&) {
VERIFY(url.scheme() == "spreadsheet");
if (url.host() == "example") {
if (url.host().template has<String>() && url.host().template get<String>() == "example"sv) {
auto example_path = url.serialize_path();
auto entry = LexicalPath::basename(example_path);
auto doc_option = m_docs.get_object(entry);
@ -122,11 +122,11 @@ HelpWindow::HelpWindow(GUI::Window* parent)
widget->add_sheet(sheet.release_nonnull());
window->show();
} else if (url.host() == "doc") {
} else if (url.host() == String::from_utf8_short_string("doc"sv)) {
auto entry = LexicalPath::basename(url.serialize_path());
m_webview->load(URL::create_with_data("text/html", render(entry)));
} else {
dbgln("Invalid spreadsheet action domain '{}'", url.host());
dbgln("Invalid spreadsheet action domain '{}'", url.serialized_host().release_value_but_fixme_should_propagate_errors());
}
};

View file

@ -264,7 +264,7 @@ Optional<Position> Sheet::position_from_url(const URL& url) const
return {};
}
if (url.scheme() != "spreadsheet" || url.host() != "cell") {
if (url.scheme() != "spreadsheet" || url.host() != String::from_utf8_short_string("cell"sv)) {
dbgln("Bad url: {}", url.to_deprecated_string());
return {};
}
@ -757,7 +757,7 @@ URL Position::to_url(Sheet const& sheet) const
{
URL url;
url.set_scheme("spreadsheet");
url.set_host("cell");
url.set_host(String::from_utf8_short_string("cell"sv));
url.set_paths({ DeprecatedString::number(getpid()) });
url.set_fragment(to_cell_identifier(sheet));
return url;