mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09: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:
parent
5acd40c525
commit
35612c6a7f
42 changed files with 131 additions and 123 deletions
|
@ -144,7 +144,7 @@ static bool build_image_document(DOM::Document& document, ByteBuffer const& data
|
|||
auto title_element = DOM::create_element(document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(head_element->append_child(title_element));
|
||||
|
||||
auto basename = LexicalPath::basename(document.url().path());
|
||||
auto basename = LexicalPath::basename(document.url().serialize_path());
|
||||
auto title_text = document.heap().allocate<DOM::Text>(document.realm(), document, DeprecatedString::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height())).release_allocated_value_but_fixme_should_propagate_errors();
|
||||
MUST(title_element->append_child(*title_text));
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, HashMap<Depre
|
|||
// FIXME: "The Quite OK Image Format" doesn't have an official mime type yet,
|
||||
// and servers like nginx will send a generic octet-stream mime type instead.
|
||||
// Let's use image/x-qoi for now, which is also what our Core::MimeData uses & would guess.
|
||||
if (m_mime_type == "application/octet-stream" && url().path().ends_with(".qoi"sv))
|
||||
if (m_mime_type == "application/octet-stream" && url().serialize_path().ends_with(".qoi"sv))
|
||||
m_mime_type = "image/x-qoi";
|
||||
} else if (url().scheme() == "data" && !url().data_mime_type().is_empty()) {
|
||||
dbgln_if(RESOURCE_DEBUG, "This is a data URL with mime-type _{}_", url().data_mime_type());
|
||||
|
@ -113,7 +113,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, HashMap<Depre
|
|||
if (content_type_options.value_or("").equals_ignoring_ascii_case("nosniff"sv)) {
|
||||
m_mime_type = "text/plain";
|
||||
} else {
|
||||
m_mime_type = Core::guess_mime_type_based_on_filename(url().path());
|
||||
m_mime_type = Core::guess_mime_type_based_on_filename(url().serialize_path());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
|
|||
if (!m_page.has_value())
|
||||
return;
|
||||
|
||||
FileRequest file_request(url.path(), [this, success_callback = move(success_callback), error_callback = move(error_callback), log_success, log_failure, request](ErrorOr<i32> file_or_error) {
|
||||
FileRequest file_request(url.serialize_path(), [this, success_callback = move(success_callback), error_callback = move(error_callback), log_success, log_failure, request](ErrorOr<i32> file_or_error) {
|
||||
--m_pending_loads;
|
||||
if (on_load_counter_change)
|
||||
on_load_counter_change();
|
||||
|
@ -275,7 +275,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
|
|||
// NOTE: For file:// URLs, we have to guess the MIME type, since there's no HTTP header to tell us what this is.
|
||||
// We insert a fake Content-Type header here, so that clients can use it to learn the MIME type.
|
||||
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> response_headers;
|
||||
auto mime_type = Core::guess_mime_type_based_on_filename(request.url().path());
|
||||
auto mime_type = Core::guess_mime_type_based_on_filename(request.url().serialize_path());
|
||||
response_headers.set("Content-Type"sv, mime_type);
|
||||
|
||||
success_callback(data, response_headers, {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue