summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-04-14 20:12:03 +0100
committerAndreas Kling <kling@serenityos.org>2023-04-15 06:37:04 +0200
commit35612c6a7f7602ff46d56bbbbc8b33b28b411409 (patch)
tree772aabbc417980448cb50df548d8ff4c2ac18ca1 /Userland/Applications
parent5acd40c525a695b353dba348a95eb0cb314a33d5 (diff)
downloadserenity-35612c6a7f7602ff46d56bbbbc8b33b28b411409.zip
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.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/3DFileViewer/main.cpp2
-rw-r--r--Userland/Applications/Browser/CookieJar.cpp4
-rw-r--r--Userland/Applications/FileManager/FileUtils.cpp9
-rw-r--r--Userland/Applications/FileManager/main.cpp2
-rw-r--r--Userland/Applications/FontEditor/MainWidget.cpp5
-rw-r--r--Userland/Applications/Help/MainWidget.cpp4
-rw-r--r--Userland/Applications/HexEditor/HexEditorWidget.cpp2
-rw-r--r--Userland/Applications/ImageViewer/main.cpp4
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp2
-rw-r--r--Userland/Applications/Presenter/PresenterWidget.cpp2
-rw-r--r--Userland/Applications/Run/RunWindow.cpp5
-rw-r--r--Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp2
-rw-r--r--Userland/Applications/Spreadsheet/HelpWindow.cpp15
-rw-r--r--Userland/Applications/Spreadsheet/Spreadsheet.cpp2
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp2
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.cpp2
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp2
17 files changed, 35 insertions, 31 deletions
diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp
index f1e0f83ac0..59fc2b8e48 100644
--- a/Userland/Applications/3DFileViewer/main.cpp
+++ b/Userland/Applications/3DFileViewer/main.cpp
@@ -146,7 +146,7 @@ void GLContextWidget::drop_event(GUI::DropEvent& event)
if (url.scheme() != "file")
continue;
- auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), url.path());
+ auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), url.serialize_path());
if (response.is_error())
return;
load_file(response.value().filename(), response.value().release_stream());
diff --git a/Userland/Applications/Browser/CookieJar.cpp b/Userland/Applications/Browser/CookieJar.cpp
index 1ad59b6453..5aacf01361 100644
--- a/Userland/Applications/Browser/CookieJar.cpp
+++ b/Userland/Applications/Browser/CookieJar.cpp
@@ -253,7 +253,7 @@ DeprecatedString CookieJar::default_path(const URL& url)
// https://tools.ietf.org/html/rfc6265#section-5.1.4
// 1. Let uri-path be the path portion of the request-uri if such a portion exists (and empty otherwise).
- DeprecatedString uri_path = url.path();
+ DeprecatedString uri_path = url.serialize_path();
// 2. If the uri-path is empty or if the first character of the uri-path is not a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.
if (uri_path.is_empty() || (uri_path[0] != '/'))
@@ -376,7 +376,7 @@ Vector<Web::Cookie::Cookie> CookieJar::get_matching_cookies(const URL& url, Depr
return;
// The request-uri's path path-matches the cookie's path.
- if (!path_matches(url.path(), cookie.path))
+ if (!path_matches(url.serialize_path(), cookie.path))
return;
// If the cookie's secure-only-flag is true, then the request-uri's scheme must denote a "secure" protocol.
diff --git a/Userland/Applications/FileManager/FileUtils.cpp b/Userland/Applications/FileManager/FileUtils.cpp
index 4e8d4c79aa..17e19ace38 100644
--- a/Userland/Applications/FileManager/FileUtils.cpp
+++ b/Userland/Applications/FileManager/FileUtils.cpp
@@ -129,13 +129,14 @@ ErrorOr<bool> handle_drop(GUI::DropEvent const& event, DeprecatedString const& d
Vector<DeprecatedString> paths_to_copy;
for (auto& url_to_copy : urls) {
- if (!url_to_copy.is_valid() || url_to_copy.path() == target)
+ auto file_path = url_to_copy.serialize_path();
+ if (!url_to_copy.is_valid() || file_path == target)
continue;
- auto new_path = DeprecatedString::formatted("{}/{}", target, LexicalPath::basename(url_to_copy.path()));
- if (url_to_copy.path() == new_path)
+ auto new_path = DeprecatedString::formatted("{}/{}", target, LexicalPath::basename(file_path));
+ if (file_path == new_path)
continue;
- paths_to_copy.append(url_to_copy.path());
+ paths_to_copy.append(file_path);
has_accepted_drop = true;
}
diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp
index 9a946bcbd4..3724bf9d82 100644
--- a/Userland/Applications/FileManager/main.cpp
+++ b/Userland/Applications/FileManager/main.cpp
@@ -202,7 +202,7 @@ void do_paste(DeprecatedString const& target_directory, GUI::Window* window)
dbgln("Cannot paste URI {}", uri_as_string);
continue;
}
- source_paths.append(url.path());
+ source_paths.append(url.serialize_path());
}
if (!source_paths.is_empty()) {
diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp
index a3dc9d71a7..9c2ef6fe17 100644
--- a/Userland/Applications/FontEditor/MainWidget.cpp
+++ b/Userland/Applications/FontEditor/MainWidget.cpp
@@ -975,8 +975,9 @@ void MainWidget::drop_event(GUI::DropEvent& event)
if (!request_close())
return;
- if (auto result = open_file(urls.first().path()); result.is_error())
- show_error(result.release_error(), "Opening"sv, LexicalPath { urls.first().path() }.basename());
+ auto file_path = urls.first().serialize_path();
+ if (auto result = open_file(file_path); result.is_error())
+ show_error(result.release_error(), "Opening"sv, LexicalPath { file_path }.basename());
}
}
diff --git a/Userland/Applications/Help/MainWidget.cpp b/Userland/Applications/Help/MainWidget.cpp
index 5ff8b23b00..23f4bcb15c 100644
--- a/Userland/Applications/Help/MainWidget.cpp
+++ b/Userland/Applications/Help/MainWidget.cpp
@@ -98,7 +98,7 @@ MainWidget::MainWidget()
m_web_view = find_descendant_of_type_named<WebView::OutOfProcessWebView>("web_view");
m_web_view->on_link_click = [this](auto& url, auto&, unsigned) {
if (url.scheme() == "file") {
- auto path = LexicalPath { url.path() };
+ auto path = LexicalPath { url.serialize_path() };
if (!path.is_child_of(Manual::manual_base_path)) {
open_external(url);
return;
@@ -246,7 +246,7 @@ void MainWidget::open_url(URL const& url)
m_web_view->load(url);
m_web_view->scroll_to_top();
- auto browse_view_index = m_manual_model->index_from_path(url.path());
+ auto browse_view_index = m_manual_model->index_from_path(url.serialize_path());
if (browse_view_index.has_value()) {
if (browse_view_index.value() != m_browse_view->selection_start_index()) {
m_browse_view->expand_all_parents_of(browse_view_index.value());
diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp
index 4d4ef49bd1..653a355c42 100644
--- a/Userland/Applications/HexEditor/HexEditorWidget.cpp
+++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp
@@ -604,7 +604,7 @@ void HexEditorWidget::drop_event(GUI::DropEvent& event)
return;
// TODO: A drop event should be considered user consent for opening a file
- auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().path(), Core::File::OpenMode::Read);
+ auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().serialize_path(), Core::File::OpenMode::Read);
if (response.is_error())
return;
open_file(response.value().filename(), response.value().release_stream());
diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp
index 2fc6686991..97376771dd 100644
--- a/Userland/Applications/ImageViewer/main.cpp
+++ b/Userland/Applications/ImageViewer/main.cpp
@@ -100,7 +100,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->move_to_front();
- auto path = urls.first().path();
+ auto path = urls.first().serialize_path();
auto result = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path);
if (result.is_error())
return;
@@ -109,7 +109,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
widget->open_file(value.filename(), value.stream());
for (size_t i = 1; i < urls.size(); ++i) {
- Desktop::Launcher::open(URL::create_with_file_scheme(urls[i].path().characters()), "/bin/ImageViewer");
+ Desktop::Launcher::open(URL::create_with_file_scheme(urls[i].serialize_path().characters()), "/bin/ImageViewer");
}
};
widget->on_doubleclick = [&] {
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index f045c84666..9f3b639bfe 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -1401,7 +1401,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
if (url.scheme() != "file")
continue;
- auto response = FileSystemAccessClient::Client::the().request_file(window(), url.path(), Core::File::OpenMode::Read);
+ auto response = FileSystemAccessClient::Client::the().request_file(window(), url.serialize_path(), Core::File::OpenMode::Read);
if (response.is_error())
return;
open_image(response.release_value());
diff --git a/Userland/Applications/Presenter/PresenterWidget.cpp b/Userland/Applications/Presenter/PresenterWidget.cpp
index 2620c7d835..92cedb0e9d 100644
--- a/Userland/Applications/Presenter/PresenterWidget.cpp
+++ b/Userland/Applications/Presenter/PresenterWidget.cpp
@@ -214,6 +214,6 @@ void PresenterWidget::drop_event(GUI::DropEvent& event)
return;
window()->move_to_front();
- set_file(urls.first().path());
+ set_file(urls.first().serialize_path());
}
}
diff --git a/Userland/Applications/Run/RunWindow.cpp b/Userland/Applications/Run/RunWindow.cpp
index 0c02bb1600..fa06057f83 100644
--- a/Userland/Applications/Run/RunWindow.cpp
+++ b/Userland/Applications/Run/RunWindow.cpp
@@ -141,9 +141,10 @@ bool RunWindow::run_via_launch(DeprecatedString const& run_input)
auto url = URL::create_with_url_or_path(run_input);
if (url.scheme() == "file") {
- auto real_path_or_error = FileSystem::real_path(url.path());
+ auto file_path = url.serialize_path();
+ auto real_path_or_error = FileSystem::real_path(file_path);
if (real_path_or_error.is_error()) {
- warnln("Failed to launch '{}': {}", url.path(), real_path_or_error.error());
+ warnln("Failed to launch '{}': {}", file_path, real_path_or_error.error());
return false;
}
url = URL::create_with_url_or_path(real_path_or_error.release_value().to_deprecated_string());
diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
index aa2d027b09..dad1e03cb9 100644
--- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
+++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
@@ -161,7 +161,7 @@ void SoundPlayerWidgetAdvancedView::drop_event(GUI::DropEvent& event)
return;
window()->move_to_front();
// FIXME: Add all paths from drop event to the playlist
- play_file_path(urls.first().path());
+ play_file_path(urls.first().serialize_path());
}
}
diff --git a/Userland/Applications/Spreadsheet/HelpWindow.cpp b/Userland/Applications/Spreadsheet/HelpWindow.cpp
index 168cc6c914..31ce668309 100644
--- a/Userland/Applications/Spreadsheet/HelpWindow.cpp
+++ b/Userland/Applications/Spreadsheet/HelpWindow.cpp
@@ -84,24 +84,25 @@ HelpWindow::HelpWindow(GUI::Window* parent)
m_webview->on_link_click = [this](auto& url, auto&, auto&&) {
VERIFY(url.scheme() == "spreadsheet");
if (url.host() == "example") {
- auto entry = LexicalPath::basename(url.path());
+ auto example_path = url.serialize_path();
+ auto entry = LexicalPath::basename(example_path);
auto doc_option = m_docs.get_object(entry);
if (!doc_option.has_value()) {
- GUI::MessageBox::show_error(this, DeprecatedString::formatted("No documentation entry found for '{}'", url.path()));
+ GUI::MessageBox::show_error(this, DeprecatedString::formatted("No documentation entry found for '{}'", example_path));
return;
}
auto& doc = doc_option.value();
- const auto& name = url.fragment();
+ auto name = url.fragment();
auto maybe_example_data = doc.get_object("example_data"sv);
if (!maybe_example_data.has_value()) {
- GUI::MessageBox::show_error(this, DeprecatedString::formatted("No example data found for '{}'", url.path()));
+ GUI::MessageBox::show_error(this, DeprecatedString::formatted("No example data found for '{}'", example_path));
return;
}
auto& example_data = maybe_example_data.value();
if (!example_data.has_object(name)) {
- GUI::MessageBox::show_error(this, DeprecatedString::formatted("Example '{}' not found for '{}'", name, url.path()));
+ GUI::MessageBox::show_error(this, DeprecatedString::formatted("Example '{}' not found for '{}'", name, example_path));
return;
}
auto& value = example_data.get_object(name).value();
@@ -115,14 +116,14 @@ HelpWindow::HelpWindow(GUI::Window* parent)
auto widget = window->set_main_widget<SpreadsheetWidget>(window, Vector<NonnullRefPtr<Sheet>> {}, false).release_value_but_fixme_should_propagate_errors();
auto sheet = Sheet::from_json(value, widget->workbook());
if (!sheet) {
- GUI::MessageBox::show_error(this, DeprecatedString::formatted("Corrupted example '{}' in '{}'", name, url.path()));
+ GUI::MessageBox::show_error(this, DeprecatedString::formatted("Corrupted example '{}' in '{}'", name, example_path));
return;
}
widget->add_sheet(sheet.release_nonnull());
window->show();
} else if (url.host() == "doc") {
- auto entry = LexicalPath::basename(url.path());
+ 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());
diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
index 94e329f367..dc693570f8 100644
--- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp
+++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
@@ -270,7 +270,7 @@ Optional<Position> Sheet::position_from_url(const URL& url) const
}
// FIXME: Figure out a way to do this cross-process.
- VERIFY(url.path() == DeprecatedString::formatted("/{}", getpid()));
+ VERIFY(url.serialize_path() == DeprecatedString::formatted("/{}", getpid()));
return parse_cell_name(url.fragment());
}
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index 1d317ce531..5b05c6bfcd 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/Userland/Applications/TextEditor/MainWidget.cpp
@@ -845,7 +845,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
if (!request_close())
return;
- auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
+ auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path());
if (response.is_error())
return;
if (auto result = read_file(response.value().filename(), response.value().stream()); result.is_error())
diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp
index f2a812c9c8..2ca4e5524d 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.cpp
+++ b/Userland/Applications/ThemeEditor/MainWidget.cpp
@@ -671,7 +671,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
if (request_close() == GUI::Window::CloseRequestDecision::StayOpen)
return;
- auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().path(), Core::File::OpenMode::Read);
+ auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().serialize_path(), Core::File::OpenMode::Read);
if (response.is_error())
return;
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index 81df461887..83a40325c6 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -279,7 +279,7 @@ void VideoPlayerWidget::drop_event(GUI::DropEvent& event)
GUI::MessageBox::show_error(window(), "VideoPlayer can only view one clip at a time!"sv);
return;
}
- auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
+ auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().serialize_path());
if (response.is_error())
return;
open_file(response.value().filename());