1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:57:35 +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

@ -141,7 +141,7 @@ Vector<DeprecatedString> Launcher::handlers_for_url(const URL& url)
{
Vector<DeprecatedString> handlers;
if (url.scheme() == "file") {
for_each_handler_for_path(url.path(), [&](auto& handler) -> bool {
for_each_handler_for_path(url.serialize_path(), [&](auto& handler) -> bool {
handlers.append(handler.executable);
return true;
});
@ -161,7 +161,7 @@ Vector<DeprecatedString> Launcher::handlers_with_details_for_url(const URL& url)
{
Vector<DeprecatedString> handlers;
if (url.scheme() == "file") {
for_each_handler_for_path(url.path(), [&](auto& handler) -> bool {
for_each_handler_for_path(url.serialize_path(), [&](auto& handler) -> bool {
handlers.append(handler.to_details_str());
return true;
});
@ -211,7 +211,7 @@ bool Launcher::open_with_handler_name(const URL& url, DeprecatedString const& ha
auto& handler = handler_optional.value();
DeprecatedString argument;
if (url.scheme() == "file")
argument = url.path();
argument = url.serialize_path();
else
argument = url.to_deprecated_string();
return spawn(handler.executable, { argument });
@ -348,7 +348,8 @@ void Launcher::for_each_handler_for_path(DeprecatedString const& path, Function<
bool Launcher::open_file_url(const URL& url)
{
struct stat st;
if (stat(url.path().characters(), &st) < 0) {
auto file_path = url.serialize_path();
if (stat(file_path.characters(), &st) < 0) {
perror("stat");
return false;
}
@ -356,11 +357,11 @@ bool Launcher::open_file_url(const URL& url)
if (S_ISDIR(st.st_mode)) {
Vector<DeprecatedString> fm_arguments;
if (url.fragment().is_empty()) {
fm_arguments.append(url.path());
fm_arguments.append(file_path);
} else {
fm_arguments.append("-s");
fm_arguments.append("-r");
fm_arguments.append(DeprecatedString::formatted("{}/{}", url.path(), url.fragment()));
fm_arguments.append(DeprecatedString::formatted("{}/{}", file_path, url.fragment()));
}
auto handler_optional = m_file_handlers.get("directory");
@ -372,10 +373,10 @@ bool Launcher::open_file_url(const URL& url)
}
if ((st.st_mode & S_IFMT) == S_IFREG && st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
return spawn(url.path(), {});
return spawn(file_path, {});
auto extension = LexicalPath::extension(url.path()).to_lowercase();
auto mime_type = mime_type_for_file(url.path());
auto extension = LexicalPath::extension(file_path).to_lowercase();
auto mime_type = mime_type_for_file(file_path);
auto mime_type_or_extension = extension;
bool should_use_mime_type = mime_type.has_value() && has_mime_handlers(mime_type.value());
@ -389,7 +390,7 @@ bool Launcher::open_file_url(const URL& url)
// Additional parameters parsing, specific for the file protocol and txt file handlers
Vector<DeprecatedString> additional_parameters;
DeprecatedString filepath = url.path();
DeprecatedString filepath = url.serialize_path();
auto parameters = url.query().split('&');
for (auto const& parameter : parameters) {