1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +00:00

AK+Everywhere: Change URL::path() to serialize_path()

This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
This commit is contained in:
MacDue 2023-04-14 20:12:03 +01:00 committed by Andreas Kling
parent 5acd40c525
commit 35612c6a7f
42 changed files with 131 additions and 123 deletions

View file

@ -192,29 +192,30 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
m_has_invalid_link = true;
return RecursionDecision::Recurse;
}
if (url.paths().size() < 2) {
if (url.path_segment_count() < 2) {
warnln("help://man URL is missing section or page: {}", href);
m_has_invalid_link = true;
return RecursionDecision::Recurse;
}
// Remove leading '/' from the path.
auto file = DeprecatedString::formatted("{}/Base/usr/share/man/man{}.md", m_serenity_source_directory, url.path().substring(1));
auto file = DeprecatedString::formatted("{}/Base/usr/share/man/man{}.md", m_serenity_source_directory, url.serialize_path().substring(1));
m_file_links.append({ file, DeprecatedString(), StringCollector::from(*link_node.text) });
return RecursionDecision::Recurse;
}
if (url.scheme() == "file") {
if (url.path().contains("man"sv) && url.path().ends_with(".md"sv)) {
auto file_path = url.serialize_path();
if (file_path.contains("man"sv) && file_path.ends_with(".md"sv)) {
warnln("Inter-manpage link without the help:// scheme: {}\nPlease use help URLs of the form 'help://man/<section>/<subsection...>/<page>'", href);
m_has_invalid_link = true;
return RecursionDecision::Recurse;
}
// TODO: Check more possible links other than icons.
if (url.path().starts_with("/res/icons/"sv)) {
auto file = DeprecatedString::formatted("{}/Base{}", m_serenity_source_directory, url.path());
if (file_path.starts_with("/res/icons/"sv)) {
auto file = DeprecatedString::formatted("{}/Base{}", m_serenity_source_directory, file_path);
m_file_links.append({ file, DeprecatedString(), StringCollector::from(*link_node.text) });
} else if (url.path().starts_with("/bin"sv)) {
} else if (file_path.starts_with("/bin"sv)) {
StringBuilder builder;
link_node.text->render_to_html(builder);
auto link_text = builder.string_view();